Java generic

Ads
 

Java generic

Java 1.5 provides number of new features to the Java Language including "Java Generics".

Java 1.5 provides number of new features to the Java Language including "Java Generics".

Java generic

     


Java 1.5 provides number of new features to the Java Language including "Java Generics". Using generics makes the application more reliable by detecting more bugs at compile time. ?Collections? framework is one of the places where Generics are most used. Until the introduction of Generics, when you take an element out of a collection they required a typecast i.e. you need to type cast it to the type of element that is stored in the collection. This is not only an inconvenient process but unsafe also. The compiler doesn't check that your have cast the element same as the collection's type. This can cause the application fail at run time.

Generic programming lets you write code that can work for many types of data. The information about the type of a collection can be provided to the compiler using Generics. Now the compiler can check the usage of collection correctly as well as you are not required to type cast the values retrieved from collection because of its support for correct auto type-casting feature.

Follow the link for complete tutorial :  Click here

 
Read more at:

http://www.javajazzup.com/JavaGenerics.shtml

 

Ads

Ads