commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pascal Schumacher (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (LANG-1159) SerializationUtils.clone cannot be used with java.util.List and "type safety"
Date Wed, 19 Oct 2016 15:24:59 GMT

     [ https://issues.apache.org/jira/browse/LANG-1159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Pascal Schumacher closed LANG-1159.
-----------------------------------

> 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)

Mime
View raw message