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.
Who is Participating?
Bijay DeoGraduate Student Research AssistantCommented:
Try this.
List<Number> numbers = new ArrayList<Number>();
CPColinSenior Java ArchitectCommented:
You're confusing the compiler with that cast. Remove it and the error will go away.
CPColinSenior Java ArchitectCommented:

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.
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
CPColinSenior Java ArchitectCommented:
I can't think of a situation where that cast makes sense; it may just be a typo.
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.