0% found this document useful (0 votes)
6 views

Generics in Java

Generics in Java allow type-safe operations on collections by making the type of objects in collections explicit. This avoids unsafe casts when retrieving objects from collections. Generics were introduced in JDK 5 and use angle brackets <> to specify types.

Uploaded by

gihanya2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Generics in Java

Generics in Java allow type-safe operations on collections by making the type of objects in collections explicit. This avoids unsafe casts when retrieving objects from collections. Generics were introduced in JDK 5 and use angle brackets <> to specify types.

Uploaded by

gihanya2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ENTERPRISE APPLICATION

DEVELOPMENT-1
Tharanga Ekanayake
BSc (Special) MIS, First Class
Generics in Java
• Generics in java were introduced as one of features in JDK 5
• The angular brackets “<>” used in generics
Java Generics Example
*The List interface represents a list of Object instances. This means that we could put
any object into a List. Here is an example:

List list = new ArrayList();

list.add(new Integer(2));
list.add("a String");

*Because any object could be added, you would also have to cast any objects
obtained from these objects. For instance:

Integer integer = (Integer) list.get(0);

String string = (String) list.get(1);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy