• 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

Generic casting

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compiler gives me a warning:

Warning: Note: C:\MyDocuments\...\MyFrame.java uses unchecked or unsafe operations.

This happens when I try to read searilized object, e.g.:

ArrayList<String> names = (ArrayList<String> objectIn.readObject();

How can I resolve this?
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because readObject() not necessary to return ArrayList<String> maybe other
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I understand that.
But, is there any way to avoid warning?
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use an annotation to suppress the warning if you know that what you are reading in is an ArrayList containing String.
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How?
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Velika Srbija:
How?



@SuppressWarning("all") public void foo() {
//your code here
}

You can get more specific than that if you like, but I'd read up on Annotations first. This feature was introduced in Java 5, so if you're using an earlier version, let me know.
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also you'll need to use a later revision of 1.5.0. The second revision doesn't support the suppress warnings, but in revisions greater than or equal to 6, it should work.
[ May 11, 2007: Message edited by: Keith Lynn ]
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I'm using JDK 6.

The syntax is
@SuppressWarnings("all")

but didn't helped. Maybe it is due to IDEA IDE which I'm using.?
reply
    Bookmark Topic Watch Topic
  • New Topic