Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

array list error

public static void main(String... aArgs){
    List<Number> numbers = (List<Number>) new ArrayList<>();


above line giving below error. I wonder what it means. How to fix it. Please advise.
SOLUTION
Avatar of CPColin
CPColin
Flag of United States of America 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
ASKER CERTIFIED SOLUTION
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
Bijay,

Since Java version 7, you no longer have to say <Number> the second time. Instead, you can use the "diamond" operator <> and save some typing. The problem here is the cast.
Avatar of gudii9

ASKER

I wonder why the author did the casting orignially in the document i read. Is there is aplace or necessity of casting ArrayList to List at all?
please advise
I can't think of a situation where that cast makes sense; it may just be a typo.