Download template template parameter - pass subclass

I have a presentation template that takes the following parameter:

@(groups: List[models.groups.AcademicGroup] 

I have an Academic Group class:

 @MappedSuperclass public abstract class AcademicGroup extends Model 

and a subclass like this:

 @Entity public class SchoolClass extends AcademicGroup 

calling my view template from inside another template already works:

 @views.html.panels.groups(schoolClasses.asInstanceOf[java.util.List[models.groups.AcademicGroup]]) 

What does not work is passed by the submaster directly through the controller:

 public static Result schoolClasses() { List<SchoolClass> schoolClasses = SchoolClass.find.all(); return ok(groups.render(schoolClasses)); } 

With this approach, I get an error message:

 The method render(List<AcademicGroup>) in the type groups is not applicable for the arguments (List<SchoolClass>) 

typecasting list does not work. Is there anything that I don't see, or is there a way to implicitly accept a subclass as a template parameter, for example, you can do this for Java generics:

 List<? extends AcademicGroup> 
+4
source share
1 answer

Thanks serejja!

Transfer List[_ <: AcademicGroup] works!

Is it equal to List<? extends AcademicGroup> List<? extends AcademicGroup>

Adding only the + sign, as Karsten mentioned, leads to a compiler error

+2
source

Source: https://habr.com/ru/post/1495718/


All Articles