+ 1
Can I cast an object read from a file - after serialization - to a Collection of my own objects ?
When I try to do that it shows me a warning saying that this cast is unchecked.
2 ответов
+ 1
this is for Collection of Strings
Collection<String> col1 = new ArrayList<>(
List.of("aa","bb","cc") );
Object object = col1;
Collection<String> col2 =
new ArrayList<String>();
if (object instanceof Collection ) {
((Collection<?>) object).forEach(o -> {
if (o instanceof String)
col2.add( (String) o ); });
}
System.out.println(col2);