Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the role of the data types inside of < > in Java? [duplicate]

Tags:

java

syntax

Possible Duplicate:
Java Generics

To be more specific, whats the role of the <String> in the following line of code?

private List<String> item = new ArrayList<String>();
like image 527
Emanuil Rusev Avatar asked Jan 20 '26 14:01

Emanuil Rusev


1 Answers

Mainly to allow the compiler to raise an error if you don't insert the right kind of data into the list or if you expect data of the wrong type from the list at the moment of extraction

But see the generics tutorial for an explanation: http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html

like image 121
Silvio Donnini Avatar answered Jan 22 '26 06:01

Silvio Donnini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!