Bruce Eckel's MindView, Inc: 3-10-04 Generics Aren't - 0 views
-
Generics seem to only solve the problem of automatically casting in and out of containers.
-
So if we write generic code that actually takes a "type of anything," that type can only be an Object, and our generic code must only call Object methods on it.
-
generics have no advantage. In fact, it's confusing if you see them used, because you scratch your head and wonder "why does he need a generic here? What is the advantage?" Answer: none.
- ...3 more annotations...
-
Java Generics use "erasure," which drops everything back to Object if you try to say "any type." So when I say <T>, it doesn't really mean "anything" like C++/ADA/Python etc. does, it means "Object."
-
That's the way of the Java world, and we are going to miss out on latent typing (it's actually possible to simulate latent typing using reflection, as I do once or twice in Thinking in Java, but it's messy and much less elegant).