这个例子被简化了。
我有一组类像这样:
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
有没有一种方法可以根据的内容推断?
class WrappedMapping[KeyType](m: KeyMapping[KeyType])
呢?现在,那个存在类型显得很突兀,这肯定会让问题变得更难回答。 - Kevin WrightWrappedMapping
没有在Mappings
中使用。 - Kevin WrightHList
中的所有映射都具有相同的键类型吗?目标有点不清楚。 - Travis Brown