Link to home
Start Free TrialLog in
Avatar of PowerEdgeTech
PowerEdgeTechFlag for United States of America

asked on

Easy ArrayList Question

Easy question:

ArrayList<String> alist = new ArrayList<String>();
ArrayList<String> alist = new ArrayList<>();
ArrayList<String> alist = new ArrayList();

All of the above SEEM to work identically.  Is that indeed the case?  Netbeans indicates that the first one is "redundant" and is happy with the last two.  Which is most correct, or is there one that is considered just good programming practice?  Is there any circumstance where one would be required over another?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PowerEdgeTech

ASKER

Weird that Netbeans doesn't give me a warning on the last one then ... just says the same as the second one: "may split declaration into a declaration and assignment".  So in 1.7, is the <> just shorthand because specifying the type again is simply redundant, and that there is never a time that the <> type in the assignment would ever differ from the <> in the declaration?
So in 1.7, is the <> just shorthand because specifying the type again is simply redundant, and that there is never a time that the <> type in the assignment would ever differ from the <> in the declaration?
Yes that's right
Thank you :)