The second one, because the first one uses the raw type instead of generics.
i.e. List
is raw, but List<?>
is generic, and you shouldn’t mix-and-match between both raws and generics.
Related Contents:
- What are Generics in Java? [closed]
- Any simple way to explain why I cannot do List animals = new ArrayList()? [duplicate]
- What does the ‘static’ keyword do in a class?
- Why don’t Java Generics support primitive types?
- What’s the reason I can’t create generic array types in Java?
- Difference between Inheritance and Composition
- Get generic type of java.util.List
- How do I address unchecked cast warnings?
- Deserialize a List object with Gson?
- How to create a generic array? [duplicate]
- Java Multiple Inheritance
- Can’t add value to the Java collection with wildcard generic type
- Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?
- Static method in a generic class?
- Instantiating generics type in java
- Java generics super keyword
- Bounding generics with ‘super’ keyword
- Generic array creation error
- Jackson and generic type reference
- How to implement enum with generics?
- What is a covariant return type?
- Generics compiles and runs in Eclipse, but doesn’t compile in javac
- Generic return type upper bound – interface vs. class – surprisingly valid code
- What are the differences between “generic” types in C++ and Java?
- Why can’t you have multiple interfaces in a bounded wildcard generic?
- Missing return statement in a non-void method compiles
- Replacing if else statement with pattern
- Is polymorphism possible without inheritance?
- Why can this generic method with a bound return any type?
- What is the difference between ‘E’, ‘T’, and ‘?’ for Java generics?
- Difference between an unbound wildcard and a raw type
- Why should I care that Java doesn’t have reified generics?
- Dynamic Generic Typing in Java
- Using Command Design pattern
- Is it possible to solve the “A generic array of T is created for a varargs parameter” compiler warning?
- Sending messages between two JPanel objects
- Type erasure, overriding and generics
- Where are generic types stored in java class files?
- Get actual type of generic type argument on abstract superclass
- Casting to generic type in Java doesn’t raise ClassCastException?
- Java Generics and Enum, loss of template parameters
- Generics, arrays, and the ClassCastException
- Can I use generics over reference types only?
- A peculiar feature of exception type inference in Java 8
- Java Enums: Two enum types, each containing references to each other?
- How would contravariance be used in Java generics?
- Virtual table/dispatch table
- Initialize Java Generic Array of Type Generic
- Java generics – get class? [duplicate]
- How to reference a generic return type with multiple bounds