Answers for "how to add generic variable in java"

0

generic variable java

List<String> yourList=new ArrayList<>();//short form of Arraylist<String> as the compiler infers the <String> from the left side of the assignment
yourList.add("Hello");
yourList.add(123);//compiler Error
String firstElement=yourList.get(0);
Integer firstElement=yourList.get(0);//compiler Error
Posted by: Guest on April-06-2021

Code answers related to "how to add generic variable in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language