Could someone please explain the JDK 1.5 warning below? It appears every
readObject( ) for a list. I've tried several things, but cannot correct the
code to eliminate the warning.
Sample code:
private List<TLoopingData> m_loopingData;
. . .
m_loopingData = (ArrayList<TLoopingData>) reader.readObject( );
The warning:
Type safety: The cast from Object to ArrayList<TLoopData> is actually
checking against the erased type ArrayList.
Thank you,
Don
On Sun's compiler you should get a warning like:
Test.java:9: warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.List<java.lang.String>
data = (List<String>)in.readObject();
^
1 warning
which should give you enough to google with.
The cast cannot be checked a runtime, therefore a warning is given. With
an up to date compiler, you can suppress the warning using
@SuppressWarnings("unchecked").
The problem is unavoidable with readObject, so I suggest writing a small
method to wrap up the nastiness in. Just so long as you know it is there.
import static com.mycompany.myproject.serial.Serial.readObject;
...
data = readObject(in);
...
package com.mycompany.myproject.serial;
/** blah */
public class Serial {
/** blah */
@SuppressWarnings("unchecked")
public static <T> T readObject(
java.io.ObjectInputStream in
) throws java.io.IOException, java.lang.ClassNotFoundException {
return (T)in.readObject();
}
}
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
>Type safety: The cast from Object to ArrayList<TLoopData> is actually
>checking against the erased type ArrayList.
see
http://mindprod.com/jgloss/compileerrormessages.html#TYPESAFETYERASED
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
m_loopingData = ArrayList<TLoopingData>() reader.readObject( );
Thanks for the info!
Don
"Thomas Hawtin" <use...@tackline.plus.com> wrote in message
news:4404ce9d$0$9241$ed26...@ptn-nntp-reader01.plus.net...
Thank you for the info!
Don
"Roedy Green" <my_email_is_post...@munged.invalid> wrote in
message news:ibca02dg9vruc0ri8...@4ax.com...