Page 1 of 1

About Question enthuware.ocpjp.v7.2.1270 :

Posted: Sat May 31, 2014 7:41 am
by kashyapa
Why

Code: Select all

ArrayList<> list = new ArrayList<>();
does not work?

i tried out it, but it says;
java.lang.RuntimeException: Uncompilable source code - illegal start of type

Re: About Question enthuware.ocpjp.v7.2.1270 :

Posted: Sat May 31, 2014 7:45 am
by admin
The whole point of generifying a class such as ArrayList is to specify what kind of objects will be stored/retrieved from it! What do you think you declaration means to the compiler?

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1270 :

Posted: Mon Jun 22, 2015 1:58 pm
by RicardoK

Code: Select all

List<String> list = new ArrayList<>(); 
list.add("A");
The explanation says that this wont compile?

Re: About Question enthuware.ocpjp.v7.2.1270 :

Posted: Mon Jun 22, 2015 8:13 pm
by admin
RicardoK wrote:

Code: Select all

List<String> list = new ArrayList<>(); 
list.add("A");
The explanation says that this wont compile?
On Java 7.