对于这种类型:
val t : (String, Array[((String, String), Double)]) = ("a", Array((("a", "b"), 1.0), (("a", "c"), 2.0)))
我是否应该也无法使用此类型定义:
val t : Tuple2[String , Array[Tuple2[[String , String] , Double]]] = ("a", Array((("a", "b"), 1.0), (("a", "c"), 2.0)))
但收到此错误:
Multiple markers at this line - identifier expected but '[' found. - wrong number of type arguments for Tuple2,
should be 2 - only classes can have declared but undefined members
定义类型时是否不允许使用Tuple2(或TupleN)?
答案 0 :(得分:4)
特别是你的问题:
Tuple2[[String , String] , Double]]
[String, String]
是胡说八道,你可能想要Tuple2[Tuple2[String , String] , Double]]
或((String , String) , Double)
答案 1 :(得分:1)
当然TupleN
可以在定义类型时使用:
你缺少Tuple2
val t : Tuple2[String , Array[Tuple2[[String , String] , Double]]] = ("a", Array((("a", "b"), 1.0), (("a", "c"), 2.0)))
^
//missing Tuple2
val t : Tuple2[String , Array[Tuple2[Tuple2[String , String] , Double]]] = ("a", Array((("a", "b"), 1.0), (("a", "c"), 2.0)))