This post originated from an RSS feed registered with Java Buzz
by Weiqi Gao.
Original Post: Generics in Java Are Evil?
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Generics are evil: The deeper I dig into the specification, the scarier it gets.
Generics solves a problem that's not there: The kinds of errors that a type safe collection prevents are the trivial programmer errors that's easily detected with unit tests. IDE's can help with the drudgery of casting when working with Collections.
JDK 1.5 generics uses erasure: None of the parameter type information is present in bytecode. Therefore instanceof doesn't work with generic types. Many intuitive programming constructs are illegal. The erasure decision was made so that Sun doesn't have to modify the JVM. They ended up modifying the JVM anyway.
The new syntax is too complicated: I've been doing Java since 1996 and am pretty good at it. I'm having trouble with the syntax. Just imagine what a new Java programmer will feel.
I would rather use C++ templates!
Dean did talk about several things that he likes: autoboxing, and the enhanced for loop. The java.util.concurrent classes were not covered tonight but were favorably mentioned.
Jeff Grigg urged programmers to take a look at C# for generics done right.
How would you like code like this?
public <T extends Comparable & Serializable> T foo(Collection<T> c1,
Collection<? extends T> c2) {
// ...
}