generic variable in java code example
Example: 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