I declare the private variable as
private List<MultipartFile> files;
When I want initialize it I do in this way:
files=new ArrayList<CommonsMultipartFile>();
you can see the CommonsMultipartFile extends the MultipartFile Interface
The compile give me error as:
Type mismatch: cannot convert from ArrayList<CommonsMultipartFile> to List<MultipartFile>
Anyone who know the reason?
If I really want to Stable the collection and inside class type, how can I do it?
Can I do similar staff in C++?
If im not mistaken, in java generics :
If you have two class
A, classB extends Aand a genericclass Generic<T>, thenGeneric<B>does not extendsGeneric<A>. That’s why your cast does not work.You could declare
filesas :With this, you should be able to do your assignment.
Edit : As it’s said in other response, this declaration would prevent to add other things than
null. Limited interest indeed…