Limitations of generics

In this section we will try to find out some of the limitations in use of generics.
  • By this time you must have understood the possible applicability of generics. Generics are used mainly when one object contains other object. It may be a simple class or a collection. You can add restriction on what can be added to other class. It is not possible to add such a restriction in other ways of reusing e.g. inheritance.
  • Generics work on objects and not on primitive data types.
  • When the instances of certain declared classes are injected using Dependency Injection (say using Spring), then you can have partial usage of generics i.e. only the declarations will be made using generics, but actual instantiation depends on if the injection supports generics.
  • Generics reduce the polymorphic nature of code. At compile time only, we finalize the concrete data types to be dealt with, this leaves little opportunity for runtime alteration.

People who read this post also read :



0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More