From ed894291a7abdbbc5ebe749f1c7ad21f2447bd3f Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Wed, 25 Aug 2010 22:22:55 +0000 Subject: [PATCH] explain why it is safe to suppress the cast warning on SerializationUtils.clone() git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@989390 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang3/SerializationUtils.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/SerializationUtils.java b/src/main/java/org/apache/commons/lang3/SerializationUtils.java index 6b3f58df2..b63725503 100644 --- a/src/main/java/org/apache/commons/lang3/SerializationUtils.java +++ b/src/main/java/org/apache/commons/lang3/SerializationUtils.java @@ -77,9 +77,15 @@ public class SerializationUtils { * @return the cloned object * @throws SerializationException (runtime) if the serialization fails */ - @SuppressWarnings("unchecked") public static T clone(T object) { - return (T) deserialize(serialize(object)); + /* + * when we serialize and deserialize an object, + * it is reasonable to assume the deserialized object + * is of the same type as the original serialized object + */ + @SuppressWarnings("unchecked") + final T result = (T) deserialize(serialize(object)); + return result; } // Serialize