Custom Search
|
Re: Maps in scala --> PLEAC --> Literals
Date: December 31, 2006
In-reply-to:
<45976DC8.1030103@xxxxxxxxxxxxxx> On Sun, Dec 31, 2006 at 07:59:04AM +0000, Andy Dwelly wrote:
> Panel p = new Panel(new FlowLayout());
> JButton b = new JButton("Press me!");
> b.setEventListener(somethingOrOther);
> p.add(b);
> JSomething foo = new JSomething(blah, blah);
> foo.setAttribute();
> foo.setOtherAttribute();
> foo.soGladIDontDoThisKindOfThingAnymore();
> p.add(foo);
>
> of course solving this needs more than just literals for maps.
Yes, it's possible to come up with much more elegant ways to write
stuff like that in Scala. IMO the biggest limitation is that there's
no nice way to refer to declaratively constructed objects that are
deeply nested. Consider:
var myLabel = null
val myWindow = new Window {
title = "My Title"
content = VBox(
new Label {
text = "A"
myLabel = this
},
new Button {
text = "Click Me"
onClick = { event =>
myLabel.text = "B"
}
}
)
}
It's all pretty neat and should be a good way to do things in Scala,
apart from the horrible hack I used to get hold of a reference to the
Label object. Of course I could have just constructed the label on
that first line instead, but then I'd be heading back in the direction
of the unstructured Java code.
/J
|