0
package list;

import java.util.ArrayList;
import java.util.List;

public class list {
    
    public static void main(String[] args)
    {
       List l = new ArrayList();
    }
}

================================================================================================

Getting squiggly for List and Array list

Arun Sudhakaran
  • 2,167
  • 4
  • 27
  • 52
Amey
  • 1
  • 1
    Modern Java doesn't like weak typing. What do you intend to *put* in the `List`? You need to tell the compiler too – g00se Jun 23 '23 at 15:50
  • 1
    Those are [*raw types*](https://docs.oracle.com/javase/tutorial/java/generics/rawTypes.html). You should not use *raw types*. That is **probably** why you get squiggles. – Elliott Frisch Jun 23 '23 at 15:52
  • 2
    Does this answer your question? [What is a raw type and why shouldn't we use it?](https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it) – OH GOD SPIDERS Jun 23 '23 at 15:55
  • What IDE are you using? Eclipse? – Reilas Jun 23 '23 at 17:41
  • I am using Eclipse. But now i am getting error while inserting or adding elements in the List. like List> l = new ArrayList(); then l.add(10);?? why?? – Amey Jun 23 '23 at 19:57
  • @g00se Wy should i tell the list what i'm putting in it?? Isn't that the actual advantage of the List that i can add any type of element in it?? – Amey Jun 23 '23 at 20:01
  • Ignoring the "squigglies" you might find somewhere along the line you or someone else might be bitten by not knowing the type in there. That's why strong typing exists, so the compiler can check the 'future' of your collection – g00se Jun 23 '23 at 20:11
  • 1
    If you want a `List` of integers you need to tell it you want a list of integers, not a `List` of capture-of; and you're still using a raw-type on the right hand side (don't do that). `List l = new ArrayList<>();` – Elliott Frisch Jun 24 '23 at 11:59

0 Answers0