Wednesday, May 18, 2011

Limitations of Collections in java

The Collections data structures are good, but ...

No primitive types. Collections data structures work only with objects, not primitive values. You can use the wrapper classes (somewhat more convenient in Java 5), use alternate libraries, or write your own class equivalents. The creation and garbage collection of these extra objects may add substantial overhead. There are several non-Sun implementations of data structures using primitives.
Pre-Java 5 Downcasting from Object In versions before Java 5 a problem is that an object returned from a data structure must be downcast to whichever type you want. This was a constant annoyance, and was a form of weak-typing, which allowed run-time type mismatches that should be caught at compile time. Generic types, as in C++ templates, are in Java 5 to enforce typing and remove the need for explicit casting. For compatibility the older versions of the classes also work.Collections frameworks have been quite complex, which gave them a reputation for having a steep learning curve. We believe that Java's new collections framework breaks with this tradition, as you will learn for yourself in the following lessons.

No comments:

Post a Comment

Chitika