> 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
[quoted text clipped - 9 lines]
> Type safety: The cast from Object to ArrayList<TLoopData> is actually
> checking against the erased type ArrayList.
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

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Don Leckie - 01 Mar 2006 15:39 GMT
Hi Tom,
Thanks for the info!
Don
>> 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
[quoted text clipped - 48 lines]
>
> Tom Hawtin
>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

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Don Leckie - 01 Mar 2006 15:42 GMT
Hi Roedy,
Thank you for the info!
Don
>>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
try
m_loopingData = ArrayList<TLoopingData>() reader.readObject( );