• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDK 1.5 Type Safety warning

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Keith, the issue is now resolved.
[ September 04, 2006: Message edited by: Saket Barve ]
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic