• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic Data Types in Eclipse

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
awesome, thanks. I'll go download that and see if that fixes my problem.

Thanks again.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I do that?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From memory it must be somewhere along the lines of "Windows/Preferences/Java/Compiler/Compliance".
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic