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.
LVL 7
gudii9Asked:
Who is Participating?
 
Bijay DeoGraduate Student Research AssistantCommented:
Try this.
List<Number> numbers = new ArrayList<Number>();
0
 
CPColinSenior Java ArchitectCommented:
You're confusing the compiler with that cast. Remove it and the error will go away.
0
 
CPColinSenior Java ArchitectCommented:
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.
0
 
gudii9Author Commented:
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
0
 
CPColinSenior Java ArchitectCommented:
I can't think of a situation where that cast makes sense; it may just be a typo.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.