import java.util.*;
class RawType
{
public static void main(
String[ ] args)
{
List<Integer> l = new ArrayList<Integer>( );
insert(l);
Object o = l.get(0); <---This works
System.out.println(o);
for(Object s :l ) <--- This doesen't work, exception thrown, why?
System.out.println(s);
}
static void insert(List l1)
{
l1.add(new Float(12.3));
}
}
I am trying to store a List<Integer> refernce in an Object using the modified for loop. When the "get( )" method is used, it correctly stores a Float in Object. However, in the modified for loop, it throws a ClassCast Exception. Why does it work for the get( ) method and not in the second case?
[ May 17, 2006: Message edited by: Aniket Patil ]