Which would be better in generics? Seems same to me, but eclipse complains to just plain List
, but not with List<Object>
.
Asked
Active
Viewed 97 times
-2

fastcodejava
- 39,895
- 28
- 133
- 186
2 Answers
3
Parameterzation should be used. It provides the compiler with details for things such as casting and autoboxing.
With this, especially when types other than Object
are used, the compiler can handle the casting and ensuring compatibility. Especially with return values and method signatures, the true type parametrized may not be exposed out of bytecode to other classes.
Do note that List<Object>
is semantically and programatically almost as useless as List
. Make sure that if you can, use a more specific type. If declaring a class or method, make sure to use a proper, specific wildcard.

nanofarad
- 40,330
- 4
- 86
- 117
1
Neither. It is better to specify the specific generic type of the list contents if possible. At the very least a common interface should be used.

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373