aspose file tools
The moose likes Beginning Java and the fly likes Parameterizing arraylist in java 1.5 version Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Parameterizing arraylist in java 1.5 version" Watch "Parameterizing arraylist in java 1.5 version" New topic
Author

Parameterizing arraylist in java 1.5 version

seshayya krishna
Greenhorn

Joined: Feb 24, 2005
Posts: 11
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

Joined: Sep 25, 2006
Posts: 38
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
Bartender

Joined: Aug 16, 2005
Posts: 12909
    
    3

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
- 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

Joined: Sep 25, 2006
Posts: 38
you should code to the interface, not the implementation


Can you explain why?? Ive never heard of that.
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
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

Joined: Sep 25, 2006
Posts: 38
Ahh cool, i didnt think about that. Thanks for the explanation! Damn now i have to change all my code
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parameterizing arraylist in java 1.5 version
 
Similar Threads
Parameterising in ArrayList throws error
Error in using JWIG
error with latest jdk
jsp:useBean Vs importing class file and using new
Collection specific elements not generic problem