+ 2

What is type eraser in java

13th Nov 2017, 4:50 AM
Rkumar
Rkumar - avatar
5 Answers
+ 4
Type erasure is the technique using which the Java compiler translates generic/parameterized type to raw type in Java generics.
13th Nov 2017, 5:30 AM
R🍁🇮🇳
R🍁🇮🇳 - avatar
+ 3
for example List<Long>list=new ArrayList<Long>() ;list. add(Long. valueOf(1));list.add(Long.valueOf(2));
13th Nov 2017, 5:55 AM
R🍁🇮🇳
R🍁🇮🇳 - avatar
+ 3
In the above example a list is created which can only contain elements of type Long and if you try to add any other type of element to this list, it will give you compile time error.
13th Nov 2017, 5:58 AM
R🍁🇮🇳
R🍁🇮🇳 - avatar
+ 2
Its my pleasure and thanks to you asking a good question
13th Nov 2017, 6:29 AM
R🍁🇮🇳
R🍁🇮🇳 - avatar
+ 1
thanks Rajeshwari for sharing valuable answers.
13th Nov 2017, 6:01 AM
Rkumar
Rkumar - avatar