[
https://issues.apache.org/jira/browse/LANG-1159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Joerg Schaible resolved LANG-1159.
----------------------------------
Resolution: Invalid
The compiler simply complains, that you did not provide a Serializable type as
argument, since the method creates a close based on serialization. All you have
to do is to provide a Serializable type. List is not serializable. However, if
you know, that you are using a serializable Implementation, cast to that one:
{format:Java}
List<Integer> list = new ArrayList<>();
List<Integer> clone = SerializationUtils.clone(ArrayList.class.cast(list));
{format}
A separate method to clone a collection is superfluous, especially if the
method should only work for serializable collection implementations.
> 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)