Here you are trying to assign a type safe class to a type unsafe class. The type safe generics accepts strictly the same type of objects as declared in the defination of the class so here only objects of Integer type is acceptable.
Also declaring the type in left or right side affects it's behaviour.
As the following code will compile but will give warning at compile time saying you are doing unsafe operation because we are trying to assign type safe generics to type unsafe class and after
Java 5.0 it will be flaged as warning.
Set s=new HashSet<Integer>();
s.add(6);
s.add(5);
for(Object i:s){System.out.println(i);
But when you declare a collection class to be type safe as follows,
Set<Integer> s=new HashSet<Integer>();
s.add(6);
s.add(5);
for(Integer i:s){System.out.println(i);
it will compile successfully and allow only Integers to be added to s. If you try to add objects of other type it will give compiler error.