About Question enthuware.ocpjp.v8.2.1825 :
Moderators: Site Manager, fjwalraven
-
- Posts: 1
- Joined: Thu Nov 05, 2015 2:09 pm
- Contact:
About Question enthuware.ocpjp.v8.2.1825 :
Could you please explain it to me why in the fifth case we can use wildcards?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1825 :
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.
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.
-
- Posts: 49
- Joined: Mon Jul 27, 2015 4:34 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1825 :
I think that's not exactly true, don't ask me why (I was messing with the code) but this compilesYou can specify generic types only when you use the new operator.
Code: Select all
PlaceHolder<String, String> ph2 = PlaceHolder.<String>getDuplicateHolder("b");
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1825 :
Removed the statement. It is too loaded.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 65 guests