When working with the standard widget toolkit (SWT), I usually use something like this to define my GridLayout:
layout.marginTop = layout.marginBottom =
layout.marginLeft = layout.marginRight =
layout.horizontalSpacing = layout.verticalSpacing = 20
It works in java but not in scala.
It gives me type mismatch; Found: Unit Required: Int.
So how can this solve it?
You cannot do this in one line in scala because the result type of an assignment expression (e.g.
a = b) isUnit. You’d have to have 6 separate calls:Why is the result type of an assignment
Unitand nmot the assigned value? I believe this was chosen for performance reasons as outlined in this question.There is a related question on assignment which points out that at declaration site, it is possible via: