About Question enthuware.ocpjp.i.v11.2.3092 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
dimitrilc
Posts: 34
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

About Question enthuware.ocpjp.i.v11.2.3092 :

Post by dimitrilc »

Assume we have

Code: Select all

class C {public List<CharSequence> test(List<CharSequence> a){return new ArrayList<CharSequence>();}}

Code: Select all

//Variant 1
//class D extends C{
//	    public List test(List a){return new ArrayList();}}

//Variant 2
//class D extends C{
//	     public List<CharSequence> test(List<CharSequence> a){return new ArrayList<CharSequence>();}}

//Variant 3
//class D extends C{
//	    public List<String> test(List<String> a){return new ArrayList<String>();}}
Would all of the three variants compile into the code below considering type erasure?

Code: Select all

//Compiled		
//class D extends C{
//	    public List test(List a){return new ArrayList();}}
Is it safe to conclude that:
If a method parameter has generic information, there can never be another method with the same signature BUT different generic information, either in the same class or super/subclass scope. The only exception is when one of method parameter does not include any generic information.
Last edited by dimitrilc on Fri Jul 10, 2020 10:11 am, edited 1 time in total.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3092 :

Post by admin »

What happened when you tried it out? Did any of the variants compiled?

dimitrilc
Posts: 34
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3092 :

Post by dimitrilc »

1 and 2 would compile, but not 3. That's how I came up with the conclusion above. Hence I asked whether the conclusion is correct?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3092 :

Post by admin »

Correct :thumbup:

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests