Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
Moderator: admin
kashyapa
Posts: 23 Joined: Thu May 08, 2014 5:27 am
Contact:
Post
by kashyapa » Sat May 31, 2014 7:41 am
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
admin
Site Admin
Posts: 10386 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Sat May 31, 2014 7:45 am
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.
RicardoK
Posts: 1 Joined: Mon Jun 22, 2015 1:56 pm
Contact:
Post
by RicardoK » Mon Jun 22, 2015 1:58 pm
Code: Select all
List<String> list = new ArrayList<>();
list.add("A");
The explanation says that this wont compile?
admin
Site Admin
Posts: 10386 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Mon Jun 22, 2015 8:13 pm
RicardoK wrote: Code: Select all
List<String> list = new ArrayList<>();
list.add("A");
The explanation says that this wont compile?
On Java 7.
Users browsing this forum: Bing [Bot] and 5 guests