I have the following problem: can someone help me (or explain where my error is). Given signs and class:
trait TextAttr[T <: {def setText(s:String); def getText : String}] {
val obj : T
def txt_= (s:String) = obj.setText(s)
def txt = obj.getText
}
class ScalaText {
private var t = ""
def setText(s:String) = t = s
def getText = t
}
Now I am creating a new class using both of them:
class ScalaTextUser extends TextAttr[ScalaText] {
override val obj = new ScalaText
}
It's good. But if I want to create something similar with the class org.eclipse.swt.widgets.Text (or any other pure Java class) I get an error. Here is the code:
class SwtTextUser(parent:Composite) extends TextAttr[Text] {
override val obj = new Text(parent, 0)
}
And this is a mistake:
arguments of type [org.eclipse.swt.widgets.Text] do not match the TextAttr type attribute of the parameter border [T <: AnyRef {def setText (String): Unit; def getText: String}]
Does anyone have an idea?
Thank you, Chris.
Chris
source
share