Java cast and convert
How do I convert ValueCallback<Uri>
to ValueCallback<Uri[]>
?
1 answers
You cannot do this conversion for 3 reasons.
1 - you can only cast if there is a relationship of extends or implements between classes. Ex:
public class Animal {
}
public class Cachorro extends Animal {
}
In this case, you can do an upcasting:
Animal animal = new Cachorro();
Or a downcasting:
Animal animal = new Cachorro();
Cachorro cachorro = (Cachorro) animal;
Here is a detail. Cast will only work, because the instance of the animal object is a dog. If you do it this way:
Animal animal = new Animal();
Cachorro cachorro = (Cachorro) animal;
Downcasting will fail.
2-in java, we can do something like this:
List<Animal> list = new ArrayList<>();
ArrayList<Animal> arrayList = (ArrayList<Animal>)list;
But if we try to do this here:
List<Animal> list = new ArrayList<Cachorro>();
An exception will be thrown. Java does not convert the type that is being used in Generics, only the object that is using Generics which in this case are Collections.
3 - you are trying to convert Uri to Uri []. That doesn't make sense. You cannot convert a common object into a list. At least I didn't see the cast of the language. What can you stand wanting to do is break a single Uri into multiple Uris. This is not a type conversion. In this case, you will need to create a converter.