generics

generics

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:
Generics
Generics
Advertisements
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
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
generics - Java Beginners
generics  simple notes on Generics as well some programmes, with its... this situation Generics provides a way to communicate the collection type.... Generics provide a mechanism for annotating type information for the use
Java Generics
.style1 { list-style-type: square; } Java Generics The Generics.... In general words, Generics allows us to create a single method for sorting... defined types. Generics permits us to catch the incompatible types during
Introduction to Generics in Java
Introduction to Generics in Java: What are the benefits of using Generics in Java? The Generics Features was added to the Java with the release of Java 5.0. The Generics was the long-waited enhancement which is added to the Java 5.0.
Wildcards in Generics
Wildcards in Generics In this section, you will learn the use wildcards or wildcard character in Generics. Problem : For better understanding of wildcards..., this is assignment is not possible in Generics. Solution : Now, the solution of above
When were generics first introduced in Java?
When were generics first introduced in Java?  Hi, I want to know when were generics first introduced in java?   Generics were introduced... the tutorial: Introduction to Generics in Java. Thanks
Generics Example Program in Java
Generics Example Program in Java explaining how you use it effectively? In this section we will explain you how you can use the Generics while writing the Java Program? The introduction to the Generics is the major step in the Java
Generics Method in Java
Generics Method in Java       After going through the example, you will be able to declare and use generic methods in Java programming language. As you already know, generic
Java Generic Iterator
Java Generic Iterator is the new feature added to the jdk1.5. It is used to generalize the Collection classes. It makes the Collection class type safe. It is used with classes, methods and interfaces. Java Generics Iterator
Java arraylist generics example and arraylist generic list
Generics is used to make  the data type safe program. It is the new feature of java 5. When the ArrayList is generalized for a specific data type, other data types cannot be added. It gives error on using the other
Java generic
to the Java Language including "Java Generics". Using generics makes...? 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
Java Glossary Term - G
Java Glossary Term - G       Java Generic Java 1.5 provides number of new features to the Java Language including "Java Generics". Using generics makes
code - Java Beginners
code  Example on exception handling with generics
Advanced Java
Advanced Java   What is the difference between byte code generated between that of Legacy collections and Generics
java - Java Interview Questions
java  What is the purpose of Generics in collection?   Hi I am sending a link where you can find details about generics/collection...;Generics provides a way for you to communicate the type of a collection
JDK 1.5 Features Diff - Java Interview Questions
JDK 1.5 Features Diff   Hi Frieds , Can u explain me d difference bn Generics and Autoboxing in jdk 1.5.  Hi Generics?Provides compile-time type safety for collections
help needed - Java Interview Questions
help needed  What are the new features added in jdk 1.5?  Hi friend, The following were the new features added in java 1.5. * Generics * Enhanced for loop * Metadata * Static import * Typesafe enums
Java - Java Interview Questions
Java  How to implement Generics Concept in programs?  Hi When you take an element out of a Collection, you must cast it to the type...(); ) if (((String) i.next()).length() == 4) i.remove(); } Generics
java - Java Interview Questions
framework better. They also added more features such as Generics, Annotations any many more. Generics made the collection framework to store the objects
compilation error - Java Beginners
generics or you are using deprecated methods. IF you want to check which lines

Ads