0

What is the purpose of "<>" in java?

I'm confused about this symbol. Is it used to define only data types of Lists?

30th Sep 2018, 10:40 AM
Shariq Bin Shoaib
Shariq Bin Shoaib - avatar
8 Réponses
+ 3
When instantiating a generic type such as a List, Set or Map, this is used to specify what actual type is stored in that particular instance. e.g. ArrayList<String> is a list of String. <> is used when the type definition is not needed,or known implicitly e.g. Entry<String, String> myEntry = new Entry<>("FirstItem", "A");
30th Sep 2018, 11:24 AM
ifl
ifl - avatar
+ 2
Naveen Deenadayalan well, yes, and ArrayList implements List. Furthermore, that's right, it is not only used for List, it is useful for any generics type. You can even create your own class with generics.
30th Sep 2018, 1:09 PM
ifl
ifl - avatar
+ 1
It is not only used to represent data types of list, it is also used to represent arraylist in java
30th Sep 2018, 1:00 PM
Naveen Deenadayalan
Naveen Deenadayalan - avatar
30th Sep 2018, 1:17 PM
Naveen Deenadayalan
Naveen Deenadayalan - avatar
+ 1
can you give me some example program to create own class with generics
30th Sep 2018, 1:21 PM
Naveen Deenadayalan
Naveen Deenadayalan - avatar
+ 1
ifl How they used in class? can you give some example?
30th Sep 2018, 1:23 PM
Shariq Bin Shoaib
Shariq Bin Shoaib - avatar
0
I didn't know anything about generic, so I googled it. Now my confusion is somehow clear. Thanks to both of you! :)
30th Sep 2018, 1:27 PM
Shariq Bin Shoaib
Shariq Bin Shoaib - avatar