All righty. I'm fairly new to
Java, but I've had extensive experience in PHP and C++.
I forget the exact name for what I'm trying to do, but what it amounts to is this. Pretend you have a Linked List class and you dont want to specify what it's a list OF (at run-time you might want a list of strings or ints or chars or whatever). The way I was told I should do this was as follows:
public class Jeff<E>
{
E data;
public Jeff(E data)
{
this.data = data;
System.out.println("test: "+data);
}
public static void main(
String[] args)
{
Jeff<Double> j = new Jeff(3);
}
}
where the <E> at the end of the class declaration signifies that you will tell it what data type you want later.
This is all well and good when I use a good, old-fashioned commandline compiler. When I put it into Eclipse, however, it underlines "Jeff<E>" in red and says "Syntax error on tokens, delete these tokens."
Does anyone know what would cause this, or how to fix it? As I say, the exact same code compiles fine using a command-line compiler.
Thanks a bunch in advance!!
P.S. Sorry 'bout the 'me's on my name, but Jeff Wright was taken...
[ January 14, 2005: Message edited by: Jeffmeme Wrightmeme ]
[ EJFH: Fixed ersatz HTML tags. ]
[ January 14, 2005: Message edited by: Ernest Friedman-Hill ]