question about Generics
Lets say I have a class ClassA and I want it to have a generics parameter E and F is an abstract class with a constructor F(double x, double y, String name). So I write, for example:
public class ClassA<E extends F> {
private E variable1;
public void method1(double x, double y) {
variable1 = new E(x, y, "string"); *
}
}
It gives me an error for the starred line. It says
Error: unexpected type
found : type parameter E
required: class
But how else can I perform such an operation?
[564 byte] By [
ak416a] at [2007-11-27 7:36:53]

I'm not a Generics guru but I think you need this:
public void method1(E obj) {
variable1 = obj;
}
That is, create your object before you call the method and pass it as a parameter.
>variable1 = new E(x, y, "string"); *
You can't do this because there's no way for the compiler to know that E has that constructor. The closest you could come would be some factory method that returns E (or maybe a super- or subclass of E--I forget which direction we'd needto go here).
jverda at 2007-7-12 19:17:24 >
