I have a view template that accepts the following parameter:
@(groups: List[models.groups.AcademicGroup]
I have my 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 within another template already works:
@views.html.panels.groups(schoolClasses.asInstanceOf[java.util.List[models.groups.AcademicGroup]])
What isn't working, is passing the sublass directly via the controller:
public static Result schoolClasses() {
List<SchoolClass> schoolClasses = SchoolClass.find.all();
return ok(groups.render(schoolClasses));
}
With this approach, I get the error message:
The method render(List<AcademicGroup>) in the type groups is not applicable for the arguments (List<SchoolClass>)
typecasting the list doesn't work. Is there anything I am missing or is there a way to implicitely accept a subclass as template parameter like you can do it for Java generics:
List<? extends AcademicGroup>
List[+models.groups.AcademicGroup](note the plus sign). - CarstenList[_ <: AcademicGroup], which is equal toList<? extends AcademicGroup>in Java - serejja