This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes My serialization class - warning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "My serialization class - warning" Watch "My serialization class - warning" New topic

My serialization class - warning

Dawid Skrzypczynski
Ranch Hand

Joined: Jun 08, 2011
Posts: 52
I wrote class to write and read serialization objects. I used generalized types but i had one warning whose i don't understand.


Program works correctly but in line 8 my Eclipse says: "Type safety: Unchecked cast from Object to T". What does this mean ?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19538

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: My serialization class - warning
Similar Threads
Why not its ClassCastException?
Serializable and Thread
please explain the output
Loading POJO object without loading library first
is static variables serialized?