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

Generic casting

 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • 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?
 
Arad Chear
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Yes, I understand that.
But, is there any way to avoid warning?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
How?
 
Alan Smithee
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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: 2409
  • Mark post as helpful
  • send pies
  • 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
  • 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.?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic