File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Generic casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generic casting" Watch "Generic casting" New topic
Author

Generic casting

Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
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

Joined: Jan 05, 2007
Posts: 98
because readObject() not necessary to return ArrayList<String> maybe other
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Yes, I understand that.
But, is there any way to avoid warning?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Jan 15, 2002
Posts: 172
How?
Alan Smithee
Greenhorn

Joined: Mar 21, 2006
Posts: 23
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

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Jan 15, 2002
Posts: 172
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.?
 
wood burning stoves
 
subject: Generic casting