4
votes

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>
1
If I'm not mistaken, the same thing in Scala (and therefore, in the template) would be List[+models.groups.AcademicGroup] (note the plus sign). - Carsten
Try passing a List[_ <: AcademicGroup], which is equal to List<? extends AcademicGroup> in Java - serejja

1 Answers

2
votes

Thanks to serejja!

Passing List[_ <: AcademicGroup] works!

This is equal to List<? extends AcademicGroup>

Adding just a + sign as Carsten mentioned leads to a compiler error