Collection_ArralyList_Generiecs1.htm |
ArrayList is a raw type over ArrayList<T> generic type
|
Warnings :Type Safety and others
|
Eclipse prompts guides you about Type Safety and resolutions. The image below shows the possible resolution of raw to generic type. |
Complete Code :
import java.io.*; import java.lang.reflect.*; import java.util.*; public class ClassTemplate1 { public String str1; private String str2; public ClassTemplate1() { // TODO Auto-generated constructor stub str2="encapsulated strictly Private scope"; System.out.println(str2); } public static void main(String[] args) throws Exception { // TODO Auto-generated method stub try{ System.out.println(" Arrays List string objects---"); ArrayList<String> str1 = new ArrayList<String>(); str1.add("Tom"); str1.add("Pan"); str1.add("Steve"); System.out.println("Processing Generics type"); Process.display(str1); // raw type ArrayList str2 = new ArrayList(); str2.add("chemistry"); str2.add("Histroy"); str2.add("English"); //calling static class directly with class name System.out.println("Processing raw type"); Process.display(str2); }catch(NumberFormatException e){ // } } } //Class processing string array list class Process{ Process() {} // constructor public static void display(ArrayList |
Run time Views : |