Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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
 
PREVIOUS NEXT
Tagged: #generic #variable #java
ADD COMMENT
Topic
Name
8+6 =