I have a generic in a function like so:
@import java.util.List;
@(field:List[_], min:Int=1)(f: (_, Int) => Html)
@{
(0 until math.max(if (field.isEmpty) 0 else field.size, min))
.map(i => f(field.get(i),i))
}
When i run this code, i get this really really unhelpful error message:
type mismatch; found : _$1 required: _$2
I don't know what this means, but the error seems to be with field.get(i)
- any ideas how to resolve this?
your block take two parameter lists:
If you assume your field hold list of something with type exact same with first parameter should feed in f, you can define your function like:
def convertSomethingGenericToHtml[T](field: List[T], min: Int = 1)(f: (T, Int) => Html) {
(0 until math.max(if (field.isEmpty) 0 else field.size, min)).map(i => f(field.get(i),i))
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.