You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Stefan Cordes (JIRA)" <ji...@apache.org> on 2015/07/27 13:13:05 UTC
[jira] [Created] (LANG-1159) SerializationUtils.clone cannot be
used with java.util.List and "type safety"
Stefan Cordes created LANG-1159:
-----------------------------------
Summary: SerializationUtils.clone cannot be used with java.util.List and "type safety"
Key: LANG-1159
URL: https://issues.apache.org/jira/browse/LANG-1159
Project: Commons Lang
Issue Type: Improvement
Affects Versions: 3.3.2
Reporter: Stefan Cordes
Priority: Minor
Having a
java.util.List<Integer> someElements;
and wanting to clone with
deepClone = SerializationUtils.clone(someElements);
gives error
"is not a valid substitute for the bounded parameter <T extends Serializable> "
Casting to Serializable:
deepClone = SerializationUtils.clone((Serializable)someElements);
gives error
"Type mismatch: cannot convert from Serializable to List<Integer>"
and finally
deepClone = (java.util.List<Integer>) SerializationUtils.clone((Serializable)someElements);
gives warning
"Type safety: Unchecked cast from Serializable to List<Integer>"
Please add a Method to clone Collections in SerializationUtils:
@SuppressWarnings("unchecked")
public static <T extends Collection<S>, S extends Serializable> T cloneCollection(T aCollection) {
// Assuming Serializable implementation of Collection is used (e.g. ArrayList)
return (T) clone((Serializable) aCollection);
}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)