Page 1 of 1

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

Posted: Fri Jul 10, 2020 1:35 am
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.

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

Posted: Fri Jul 10, 2020 1:56 am
by admin
What happened when you tried it out? Did any of the variants compiled?

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

Posted: Fri Jul 10, 2020 10:17 am
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?

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

Posted: Fri Jul 10, 2020 11:26 am
by admin
Correct :thumbup: