" I see no difference in the following: Object o = new LinkedList(); ...">

The difference between "list instance" and "o list instance <?>"

I see no difference in the following:

    Object o = new LinkedList<Long>();

    System.out.println(o instanceof List); 
    System.out.println(o instanceof List<?>);

Is there any practical use instanceof List<?>when instanceof Listit cannot be used instead of vise versa?

+3
source share
2 answers

No difference. The wildcard is erased at compile time.

+8
source

According to this blog, the answer is "they are exactly the same":

javac , ; , , (. ). , , w.r.t. .

Object o = new ArrayList<String>();
List<?> list_string = (List)o; //same as (List<?>)o
boolean b = o instanceof List; //same as o instanceof List<?>
+3

All Articles