Page 1 of 1

About Question enthuware.ocpjp.v8.2.1824 :

Posted: Sat Jul 16, 2016 8:24 am
by fodpeter@gmail.com
Hi

I think the explanation of "1Z0-809, Test 2, question 54" contains a typo: the <X> declaration is mandatory before the return type.

Peter
public static <X> PlaceHolder<X, X> getDuplicateHolder(X x){
    return new PlaceHolder<>(x, x); //use diamond operator because we already know that X is a generic type.
}

Re: About Question enthuware.ocpjp.v8.2.1824 :

Posted: Sat Jul 16, 2016 8:36 am
by admin
You are right. Fixed.
thank you for your feedback!
Paul.

Re: About Question enthuware.ocpjp.v8.2.1824 :

Posted: Fri Sep 30, 2016 4:46 am
by vlive07@gmail.com
return new PlaceHolder<X, X>(x, x);

i don't understands this . as per i know you cant instantiate generic. Kindly give example :thumbup:

Re: About Question enthuware.ocpjp.v8.2.1824 :

Posted: Fri Sep 30, 2016 10:33 am
by admin
I am not sure what you mean by, "You can't instantiate generic".
Here is an example from official Java tutorial: https://docs.oracle.com/javase/tutorial ... types.html

Code: Select all

Pair<String, Integer> p1 = new OrderedPair<String, Integer>("Even", 8);
Pair<String, String>  p2 = new OrderedPair<String, String>("hello", "world");
HTH,
Paul.