Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help on generics

 
Analise Ramil
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please explain me why I am getting these errors and how I could fix it?

***************************************************************
AList.java:23: type ArrayList does not take parameters
List<Integer> iL = new ArrayList<Integer>();
^
.\ArrayList.java:22: incompatible types
found : ArrayList
required: java.util.List<java.lang.Integer>
List<Integer> iL = new ArrayList();
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
***************************************************************

The code below came from S&B book page 559, with little modification.



Thanks in advance.
 
Rekha Srinath
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Java 4?

The code compiles fine for me. I am using Java6,Update7.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Analise! Welcome to javaranch.

As far as your problem goes, is the code you put here exactly what you wrote. I feel that you named your own class as ArrayList.

This can be seen from your error too

AList.java:23: type ArrayList does not take parameters
List<Integer> iL = new ArrayList<Integer>();
^
.\ArrayList.java:22: incompatible types
found : ArrayList
required: java.util.List<java.lang.Integer>
List<Integer> iL = new ArrayList();
^
Note: Some input files use unchecked or unsafe operations.
 
Analise Ramil
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
Thanks for your reply.

Im using java java 5.
Hmmm I still can't have it working.

I named the class originally as ArrayList.java but later renamed it.
I will try to restart my pc and see if I can get this work.

Thanks again.
 
Analise Ramil
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again.

I got the code working now. I deleted ArrayList.java from my drive, the original file name. Thanks for pointing it out to me Ankit.

However, I am getting compiler note as follows:

**************************************
c:\JavaWork>javac AList.java
Note: AList.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
**************************************

Are you getting the same note Rekha?

Can anyone explain how and if there is something I can do to get a clean compilation (no note).
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not an error. It is a warning...
 
Analise Ramil
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ankit Garg:
This is not an error. It is a warning...


Ok Ankit! Got it, thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic