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




Have Programming Question? Ask it here!
 
 
 


deepa
generics
2 Answer(s)      5 years and a month 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
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
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... in Generics. Solution : Now, the solution of above problem is : List<?> obj
Java Notes: Generics
Java Notes: Generics Using predefined generic classes is commmon, writing them is less common. Generics are primarily a way for library authors... static/strong typing and the introduction of generics allows even stronger
Generics Method in Java
Generics Method in Java       After going through the example, you will be able to declare... it as return type.         Code for Java Method - Generics
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
Collections Exercise 4 - Word Translator (Generics)
Java: Collections Exercise 4 - Word Translator (Generics) Name ____________________________________ For the purposes of this exercise, the only data structures that need to be considered are: array, ArrayList, LinkedList, HashSet
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 5 Features
been extended in two directions. Generics -- Specifying the object type... rewritten in Java 5 using generics Java 5 let's you specify the type of element... that can be. // Same example using generics. List<String> greetings
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
Self-reloading XML Property Files - Java Tutorials
mentioned that I like generics. To me, they improve the Java language... code with generics quite easy, because IntelliJ IDEA assists me... the cost of initially writing the code. Can generics help
Advanced Java Tutorials
Work the latest JDBC technology Learn Java Generics ADS4ThUnitADS... of your advance java study. Generics Introduction to Generics... Methods Strengths and Weaknesses of Generics Legacy Code and 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
 

 

 

DMCA.com