For both declarations we are going to get warning message
import java.util.*;
class
Test {
public static void main(String [] args) {
ArrayList sampleList = new ArrayList<Integer>(); //#1 Warning
//ArrayList<Integer> sampleList = new ArrayList(); //#2 Warning
int x = 5;
sampleList.add(5);
for(Object obj:sampleList)
System.out.println(obj);
}
}
Note: Test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
ie at #1 we are assigning generic(type safe) to non generic and
at # 2 doing otherway so both are unsafe or unchecked opearations