Page 1 of 1

About Question enthuware.ocpjp.v8.2.1265 :

Posted: Thu Mar 10, 2016 2:15 pm
by javalass
Regarding option 2:

Code: Select all

List<String> list = new ArrayList<>(); 
list.add("A"); 
list.addAll(new ArrayList<>());
with the explanation
Java SE 7 supports limited type inference for generic instance creation; you can only use type inference if the parameterized type of the constructor is obvious from the context. In this option, the last line will not compile because list.addAll() method expects Collection<? extends String> and so the compiler cannot infer the generic type for ArrayList.
This only applies to Java 7. In Java 8, the code above compiles and runs fine. Mind you, they do say you should avoid doing it, so I suppose this wouldn't be considered "appropriate use of generics".

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

Posted: Thu Mar 10, 2016 2:22 pm
by javalass
I just noticed this is a duplicate of viewtopic.php?f=38&t=3562, sorry.

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

Posted: Thu Mar 10, 2016 10:17 pm
by admin
Fixed in the upgrade question bank.
thank you for your feedback!