Java Generics

7/6/2004 8:48:20 PM

Java Generics

Responding to my last post on using my experience with generics in Whidbey, one Java enthusiast comments:

It is interesting that in .NET Generics tie you to the release date of the runtime but in the Java world the release of Generics with 1.5 will not impact what runtimes you can run on because it is implemented as a compiler feature. Being biased to the Java side of things I prefer the byte code compatibility of the Java world.

The issue with byte code compatibility is not as important in .NET world as in Java, since application vendors currently are expected to install the .NET redistributable with their application. On the other hand, version 1.1 is already installed on 70 million Windows machine through prior installations of existing .NET applications or Windows Update. Relying on the Whidbey runtime instead of Everett (v1.1) does introduce more friction as Whidbey is less likely to have been previously installed than Everett. After Longhorn, which will ships with a standard runtime, compatibility will become more important.

My initial reaction with the implementation of Java generics in the Tiger release was negative. That implementation preserves byte code compatibility at the expense of performance. In particular, primitive types are boxed rather than stored natively in Java's generic collection.

I naturally regarded it as another example of Java having lost its techological leadership. But, after thinking about this, and using generics, I suspect that the reality is quite different.

 Sun is full of smart developers and it was probably the best decision to be made. Had I been in their shoes, I may have made the same decision. Nothing in the design precludes Java from introducing a more performant implementation in a future VM, and at the same time generics will still have downlevel support in the current VM. There are also real performance improvements from Java's Tiger implementation: Reference types, unlike primitive type, should behaved as optimally as in the .NET world, as the main cost, that of casting, is eliminated in both implementations.







Net Undocumented is a blog about the internals of .NET including Xamarin implementations. Other topics include managed and web languages (C#, C++, Javascript), computer science theory, software engineering and software entrepreneurship.

Social Media