aspose file tools
The moose likes Java in General and the fly likes Generic casting Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Generic casting" Watch "Generic casting" New topic
Author

Generic casting

Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 171
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: 171
Yes, I understand that.
But, is there any way to avoid warning?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
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: 171
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: 2341
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: 171
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.?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Generic casting
 
Similar Threads
Mixing Legacy with Generic Code
How do you create an array of typesafe-collections?
Generics Generics Generics !!!
doubt about generic collection