Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic Data Types in Eclipse

 
Jeffmeme Wrightmeme
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you work with Java 5 and use generics?

Then you need the latest milestone build of Eclipse 3.1 - earlier versions don't support anything above JDK 1.4.
 
Jeffmeme Wrightmeme
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
awesome, thanks. I'll go download that and see if that fixes my problem.

Thanks again.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will also need to adjust the compliance setting of the Eclipse compiler, btw.
 
Jeffmeme Wrightmeme
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I do that?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From memory it must be somewhere along the lines of "Windows/Preferences/Java/Compiler/Compliance".
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff,
On the display name, you can actually get "Jeff Wright." Our system lets you have the display name you want even if someone else has it. It just doesn't let you have the same login name.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic