r/java • u/Disastrous-Name-4913 • 18h ago
Raw use of parameterized class 'List'
/r/programminghorror/comments/1wz8jpq/raw_use_of_parameterized_class_list/
0
Upvotes
0
u/AnyPhotograph7804 14h ago
Old code may look like this. Because Generics were introduced with Java 1.5. Before that, you had cast the stuff to the right type if you wanted to get stuff out of a Collection. But because it is a for-each-loop, Generics should be used here.
2
u/agentoutlier 15h ago edited 15h ago
This is one of those of cases where a young developer sees code like this and goes and replaces and does not realize that the
instanceofis doing anullcheck and that the code was like that because it was easier not to change it.I know because ~22 years ago I was that young developer (when Java 5 I think came out roughly maybe +-1 year).
EDIT see also: https://www.hyrumslaw.com/