This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Parameterizing arraylist in java 1.5 version  RSS feed

 
seshayya krishna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Mike Cole
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!