make SerializationUtils.clone() type-safe
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@989199 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
52bea417c5
commit
c3e3feeaa1
|
@ -77,8 +77,9 @@ public class SerializationUtils {
|
||||||
* @return the cloned object
|
* @return the cloned object
|
||||||
* @throws SerializationException (runtime) if the serialization fails
|
* @throws SerializationException (runtime) if the serialization fails
|
||||||
*/
|
*/
|
||||||
public static Object clone(Serializable object) {
|
@SuppressWarnings("unchecked")
|
||||||
return deserialize(serialize(object));
|
public static <T extends Serializable> T clone(T object) {
|
||||||
|
return (T) deserialize(serialize(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
|
|
@ -340,7 +340,7 @@ public class SerializationUtilsTest extends TestCase {
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
public void testClone() throws Exception {
|
public void testClone() throws Exception {
|
||||||
Object test = SerializationUtils.clone(iMap);
|
HashMap<?, ?> test = SerializationUtils.clone(iMap);
|
||||||
assertNotNull(test);
|
assertNotNull(test);
|
||||||
assertTrue(test instanceof HashMap<?,?>);
|
assertTrue(test instanceof HashMap<?,?>);
|
||||||
assertTrue(test != iMap);
|
assertTrue(test != iMap);
|
||||||
|
|
Loading…
Reference in New Issue