4
A
回答
2
这是否不符合您的需求?
class A[T](ts: Seq[T])
6
该类的成员不在构造函数的参数声明中。
这是接近你可以得到:
scala> trait T { type T; val a: T }
defined trait T
scala> def A[X](x: X) = new T { type T = X; val a = x }
A: [X](x: X)Object with T{type T = X}
scala> A[Int](0)
res0: Object with T{type T = Int} = [email protected]
scala> A[String](0)
<console>:10: error: type mismatch;
found : Int(0)
required: String
A[String](0)
^
scala> class AA[X](val a: X) extends T { type T = X }
defined class AA
scala> new AA[Int](0)
res5: AA[Int] = [email protected]
scala> new AA[String](0)
<console>:10: error: type mismatch;
found : Int(0)
required: String
new AA[String](0)
^
+0
我不确定这种类型的理论..你可以解释一下如何实现OP的目标吗? – 2011-12-15 02:34:10
相关问题
- 1. scala抽象类型参数化`this.type`
- 2. 在scala中混合类型参数和抽象类型
- 3. Scala - 可以扩展的抽象基类中的参数类型
- 4. 抽象类型与类型参数
- 5. 使用什么? Scala中的参数化类,抽象类或未定义类型?
- 6. 类型参数化抽象类
- 7. Scala:从抽象父类参数中导出正确的子类
- 8. 覆盖抽象Scala的类型
- 9. 类型参数在scala中伴随对象的类型约束
- 10. scala类的构造函数和抽象类型
- 11. Scala抽象类型和多态性
- 12. 获取Scala类型的类型参数
- 13. 使用抽象类型的Scala结构类型
- 14. Java抽象方法参数类型
- 15. Scala的泛型类[_]参数
- 16. scala:抽象类实例化?
- 17. 引用Scala中的类构造函数中的抽象类型成员
- 18. 与抽象类型交换类型参数
- 19. Kotlin抽象类与泛型参数和使用类型参数的方法
- 20. Scala中的特征与抽象类
- 21. 具有抽象类参数的抽象方法的Java抽象类
- 22. Scala类型参数重复
- 23. Scala:参数匹配类型
- 24. 使用结构图替换泛型类型参数中的抽象类型
- 25. 抽象数据类型
- 26. scala抽象类:无法访问构造函数参数
- 27. 抽象类参考
- 28. 的Java抽象类/接口和指定类型参数
- 29. 抽象类 - 儿童类型
- 30. Scala中的类型参数化
这就是我试图移动远离。这就是我当前的实现如何工作,但我想将参数化类型视为对我需要做的很多通用实例(例如:List [String],List [Int],List [NyanCat])有用。等等)而不是通常少于10个用例(例如:TV [NTSC],TV [PAL],TV [Digital])的东西。 – duckworthd 2011-12-15 04:27:34