This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Dynamic Data Types in Eclipse  RSS feed

 
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 ]
 
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".
 
author & internet detective
Marshal
Posts: 38508
653
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!