+ 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.

19th Jul 2021, 8:51 AM
Abdelhaq El Amraoui
Abdelhaq El Amraoui - avatar
2 Réponses
+ 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);
19th Jul 2021, 10:16 PM
zemiak