Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


deepa
generics
2 Answer(s)      5 years and 9 months ago
Posted in : Java Beginners



Advertisement
View Answers

June 18, 2009 at 11:52 AM


Hi Friend,

If you want to take an element from the Collection, you have to cast the type of element that is stored in the collection.The compiler does not check that your cast is the same as the collection's type or not, which makes the cast fail at run time.To overcome this situation Generics provides a way to communicate the collection type to the compiler which aware the compiler about the element type of the collection, and can insert the correct casts on values being taken out of the collection.

Generics provide a mechanism for annotating type information for the use of the compiler. By providing this information, the compiler can in turn verify the consistent use of "genericized" classes and automatically insert explicit casts, eliminating the need for programmers to do so manually.

The Generics makes its information available only at compile time and not translated into the compiled bytes. This allows genericized classes to interoperate cleanly with legacy, or raw, types.

It has the ability for library authors to express their intent more cleanly. Generics help to enforce the contents of collections and other genericized classes.

Generics can be used in more than just collection classes which allows developers to write their own genericized classes and genericized methods with generics.

Thanks


September 13, 2011 at 8:13 PM


hello sir/madam,

i am looking to develop mobile application project for some good practice, please advice me.

thanks



Related Tutorials/Questions & Answers:
Advertisements
eraser type generics in java
eraser type generics in java  Explain eraser type generics in java with example
Why Generics was introduced in Java?
Why Generics was introduced in Java?  Hi, Why Generics was introduced in Java and what is was its motive? Thanks   Generics were... for compile time type checking. Read the tutorial for more details of Generics
Advertisements
 

 

 

DMCA.com