| Author |
My serialization class - warning
|
Dawid Skrzypczynski
Ranch Hand
Joined: Jun 08, 2011
Posts: 50
|
|
Hi,
I wrote class to write and read serialization objects. I used generalized types but i had one warning whose i don't understand.
Code:
Using:
Program works correctly but in line 8 my Eclipse says: "Type safety: Unchecked cast from Object to T". What does this mean ?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
Because of type erasure, the generic type is no longer available at runtime. That means that the JVM cannot check at that point if the cast is valid. If the object is not a T then you will get a ClassCastException, only at a different point in your code. It will be harder to trace back the cause to the unsafe cast.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: My serialization class - warning
|
|
|