• 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

Parameterizing arraylist in java 1.5 version

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to parameterisze the arraylist as follows. I am getting compilation error.

1. About my environment I had installed java 1.5 and JRE . I had checked the java version it shows 1.5

2. In my Eclipse build path, I had added all necessary jar file.

But still the following throws Compilation error .

private ArrayList<Item> myStore = new ArrayList<Item>();


Item is a class which contains getter and setters. Further it is in the same default package (located in the same work space).

1. I am importin java.util.* package.

I am getting the following error messages.

Multiple markers at this line
Syntax error on token "<" , ( expected
Syntax error on token "(" invalid expression
Syntax error on tokens delete these tokens

Can some one help me immediately ?

Thanks
Murali
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that should work.
Maybe the error is before that?

Anyway, you can allways make a new file(without anything else) and try if it works there. If it doesen't work there too, you have another problem...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which version of Eclipse are you using?

Maybe you need to tell Eclipse that you want to use Java 5.0 features. Go to Window / Preferences / Java / Compiler and check what "Compiler compliance level" is set to.
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- do not use the default package (it is discouraged and might give you troubles later on)
- make sure you have javac 1.5 (since you compile with javac and not with java)
- if you use an IDE to compile, then make sure it uses 1.5 to compile your project (not just 1.5 to run the IDE) (in Eclipse "Project" -> "Properties" -> "Java Compiler"
- you should code to the interface, not the implementation

- have fun :-)

Pascal
 
Mike Cole
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

you should code to the interface, not the implementation



Can you explain why?? Ive never heard of that.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can you explain why??



maybe i translated this wrong ?...



What i wanted to say...:as long as you do not require a specific implementation (e.g. if you do a lot of List operations and you found that List implementation Foo is considerably faster than implementation Bar) you should use the most generic type possible (and this would be List or even Collection if you do not care about order).

Like this you can change the implementation without changing the interfaces/you do not tie your code to a specific implementation.

Pascal
 
Mike Cole
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh cool, i didnt think about that. Thanks for the explanation! Damn now i have to change all my code
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Damn now i have to change all my code :-)



Yes. Do it right now. Or your code will stop to work in 5 minutes :-)

Have a nice day.

Pascal
 
reply
    Bookmark Topic Watch Topic
  • New Topic