[英]How to use nested generic types in Scala as method return type
I have a few methods that would like to use a nested generic type as its return type. 我有几种方法想使用嵌套的泛型类型作为其返回类型。
import scala.language.higherKinds
trait DBClient {
def execute[T[U] <: DataStoreItem[U]](ops: ScanamoOps[Result[T]]): Future[U]
}
But this doesn't work. 但这是行不通的。 I am not able to use
U
in my return Type. 我不能在返回类型中使用
U
Is there any other way to define a method like the one above where I can use a nested type U
in my return type. 还有其他方法可以定义上述方法,在该方法中我可以在返回类型中使用嵌套类型
U
I also Tried: 我也尝试过:
trait DBClient {
def execute[U, T <: DataStoreItem[U]](ops: ScanamoOps[Result[T]]): Future[U]
}
Which doesn't work either. 这也不起作用。 Thanks for helping, I am very new to scala generics and higher order types.
感谢您的帮助,我对scala泛型和高阶类型非常陌生。 So please excuse my ignorance.
所以,请原谅我的无知。
I got it almost right. 我几乎说对了。
import scala.language.higherKinds
trait DBClient {
def execute[T[U0] <: DataStoreItem[U0], U](ops: ScanamoOps[Result[T[U]]]): Future[U]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.