Stange compilation error.
Hello,
I am going through the Generics pdf off the Java API and thought I would try some of the sample code that it contains. I created this class
import java.util.*;
public class Test
{
public static <T> void copy(List<T> dest, List<? extends T> src)
{
}
public Test()
{
}
}
class Test2
{
public static <T, S extends T> void copy(List<T> dest, List<S> src)
{
}
}
interface Part
{
}
class Guillotine implements Part
{
}
class Blade implements Part
{
}
class Main
{
Collection <Part> c = new ArrayList<Part>();
Part a = new Guillotine();
Part b = new Blade();
c.add (a);
c.add (b);
Collection <Part> k = c;
}
A error apon compilation id generated for the lines
c.add (a);
c.add (b);
Y:\>javac Test.java
Y:\>javac Test.java
Test.java:38: <identifier> expected
c.add (a);
^
Test.java:39: <identifier> expected
c.add (b);
^
If I change thos two lines to
boolean c1 = c.add (a);
boolean c2 = c.add (b);
It compiles without any errors. What the deal? Do you have to colelct the return data from a Collection.add? I've been scatching my head over this for a few hours and have no idea. I have never had this issue before. I have stripped all the generics code out and it still doesn't compile.
thanks,
Tyson Oswald

