I currently get returned an ImmutableSet from a function call (getFeatures()) and due to the structure of the rest of my code to be executed later on- it would be much easier to change this to a List. I have tried to cast it which produces a runtime exception. I have also looked around for a function call to convert it to a list to no avail. Is there a way to do this? My most recent [failed] attempt is shown below:
ImmutableSet<FeatureWrapper> wrappersSet = getFeatures();
List<FeatureWrapper> wrappers = (List<FeatureWrapper>) wrappersSet;
I have found wrapperSet.asList() which will give me an ImmutableList however i would much rather prefer a mutable list
You can't cast a Set<T>
into a List<T>
. They are entirely-different objects. Just use this copy constructor which creates a new list out of a collection:
List<FeatureWrapper> wrappers = new ArrayList<>(wrappersSet);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With