Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDK 1.5 Type Safety warning

 
Saket Barve
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am getting type safety warning in my code, relevant part of which is reproduced below:



The last line gives a warning stating:
"The method add(Object) belongs to the raw type ArrayList. References to generic type ArrayList<E> should be parameterized."

How does one get around this warning? The Quick Fix option in Eclipse doesn't seem to come up with very helpful options.

Saket
[ September 04, 2006: Message edited by: Saket Barve ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Saket Barve:
Hello,

I am getting type safety warning in my code, relevant part of which is reproduced below:



The last line gives a warning stating:
"The method add(Object) belongs to the raw type ArrayList. References to generic type ArrayList<E> should be parameterized."

How does one get around this warning? The Quick Fix option in Eclipse doesn't seem to come up with very helpful options.

Saket

[ September 04, 2006: Message edited by: Saket Barve ]


Instead of making the type of itemAddArrayList the raw type ArrayList, make it the same parameterized type you use on the right.
 
Saket Barve
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Keith, the issue is now resolved.
[ September 04, 2006: Message edited by: Saket Barve ]
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

To avoid -Xlint:unchecked,

List<Type> Obj=new ArrayList<Type>();

Class<Type> Obj=new Class<Type>();
Class<Type> Obj=new SubClass<Type>();

Interface<Type> Obj=new ConClass<Type>();

One can use ? ( wild char) in Left hand side of = ( Declaration ) but not in Right hand side.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic