About Question enthuware.ocpjp.v8.2.1825 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
361gradus
Posts: 1
Joined: Thu Nov 05, 2015 2:09 pm
Contact:

About Question enthuware.ocpjp.v8.2.1825 :

Post by 361gradus »

Could you please explain it to me why in the fifth case we can use wildcards?

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

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

Post by admin »

If you look at the right hand side of the assignment, you will notice that it is not using generics at all. This means that it is the programmers responsibility to make sure the object created complies with the requirements of the type of the variable. The compiler will not check for type safety. This is an unsafe operation.

Therefore, the compiler will accept even the following statement:
PlaceHolder<Integer, String> ph5 = new PlaceHolder(10, 10); //5

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

mrmuiz
Posts: 49
Joined: Mon Jul 27, 2015 4:34 am
Contact:

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

Post by mrmuiz »

You can specify generic types only when you use the new operator.
I think that's not exactly true, don't ask me why (I was messing with the code) but this compiles

Code: Select all

PlaceHolder<String, String> ph2 = PlaceHolder.<String>getDuplicateHolder("b");

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

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

Post by admin »

Removed the statement. It is too loaded.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

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