wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need help on generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need help on generics" Watch "Need help on generics" New topic
Author

Need help on generics

Analise Ramil
Greenhorn

Joined: Sep 02, 2008
Posts: 4
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

Joined: Sep 13, 2008
Posts: 178
Are you using Java 4?

The code compiles fine for me. I am using Java6,Update7.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Analise Ramil
Greenhorn

Joined: Sep 02, 2008
Posts: 4
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

Joined: Sep 02, 2008
Posts: 4
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

This is not an error. It is a warning...
Analise Ramil
Greenhorn

Joined: Sep 02, 2008
Posts: 4
Originally posted by Ankit Garg:
This is not an error. It is a warning...


Ok Ankit! Got it, thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help on generics
 
Similar Threads
Conversion of Arrays to List - code causing compiler error
Do arrays auto-expand if created using List.toArray()
Understanding List and String.
Using for..each loop on Object[]
Why can't we use the IS-A test for the enhanced for-loop?