类型:
def radioGroup[T](values: Array[T], textProvider: T => String)(setups:(RadioGroup[T] => Unit)*)(parent: Composite): RadioGroup[T]
def label(setups:(Label => Unit)*)(parent:Composite): Label
def contains(setups : (Composite => Unit)*) : Composite // "Pimp my library" on Composite
这有效:
new Composite(parent, SWT.NONE).contains(
label() // should have type Composite => Label
)
这不是:
new Composite(parent, SWT.NONE).contains(
radioGroup(Array(1,2), (_:Int).toString)()
// should have type Composite => RadioGroup[Int]
)
出现以下错误:
polymorphic expression cannot be instantiated to expected type;
found : => (org.eclipse.swt.widgets.Composite) => main.scala.RadioGroup[Int]
required: (org.eclipse.swt.widgets.Composite) => Unit
我可以将radioGroup
的返回类型注释为Unit
,但我不明白1)radioGroup
和label
的情况如何不同; 2)为什么错误消息中“找到”类型的开头有一个额外的箭头。