These two examples don't compile using Oracle Java 8 JDK.
The error is:
error: incompatible types: Object cannot be converted to Integer for (Integer i : foo.set )
Example 1)
import java.util.Set;
class Foo<T>
{
protected Set<Integer> set;
}
class Foo2 extends Foo
{
void doit()
{
for (Integer i : set )
{
}
}
}
Example 2)
import java.util.Set;
class Foo<T>
{
public Set<Integer> set;
public static void main( String[] args )
{
Foo foo = new Foo();
for (Integer i : foo.set )
{
}
}
}
Is it bug or feature? As I can understand generics don't work in fields оf raw type.