I am a long-term user of Java (but I am a scientist and not a professional developer) . I upgrade whenever new versions come out but often I only use a small portion of the new features at first as I don’t always have time to study everything.
Recently I learned that unless I fully understood generics I was likely to have serious dangers in using (or in this case not using them) – dangers which I was unaware of and which are not obvious. (I appreciate that I was warned by Eclipse but I didn’t understand the warning!)
The particular case in point was that it is now (since 1.5) bad practice to use raw types and that Class (rather than Class<?> or Class<MyStuff>) had serious dangers. see Why is Class<?> preferred to Class.
My question is – what others dangers am I likely to encounter and be unaware of as a result of upgrading to Java 1.5 (or 1.6, 1.7) but using my old code or style of programming?
I’ll speak about the converse (i.e. the benefits):
I’m not aware of dangers (and I’ve ported Java 1.4 codes to Java 6 without hickups as well as java 5 codes to java 6, java meaning JDK). As for warnings, it’s basically a warning (since your code will compile) and you are free to resolve these warnings.
As for as Generics is concerned, Generics are used for Compile-time checking by the compiler, i.e. once the compiler has the element type (e.g. in
Collection), it can see whether you have used the object correctly with the correct cast.Generics are implented by type erasure. They are present only at compile-time after that the compiler erases it. This is to provide interoperability with legacy codes which uses raw types (e.g.
Listin JDK 1.4).I don’t know if these would be the dangers, but it wouldn’t affect your JDK 4 applications:
And you have better performance of the Java Collections Framework.
PS the only problem migrating from JDK 1.4 to a new JDK (5 and higher) is you’ll face issues with enum (as it is a reserved keyword from JDK 5 and higher). OTher than that, you’re ok.