这个例子被简化了。
我有一组这样的类:
case class KeyMapping[KeyType](k:KeyType)
class WrappedMapping[KeyType](m:T forSome {type T <: KeyMapping[KeyType]}) {
val k:KeyType = ???
}
在以下代码中,类型被正确推断:
val w = new WrappedMapping(KeyMapping("key"))
//The statement below gives the correct error
//type mismatch;
// found : w.k.type (with underlying type String) required: Nothing
//val test1:Nothing = w.k
我不知道如何正确推断以下类型:
class Mappings[KeyType, L <: HList](mappings:L) {
val k:KeyType = ???
}
val m = new Mappings(KeyMapping("key1") :: KeyMapping("key2") :: HNil)
// should not compile, k should be of type String
val test2:Nothing = m.k
有没有办法可以KeyType
根据内容推断HList
?