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
) is Unit
. You'd have to have 6 separate calls:
layout.marginTop = 20
layout.marginBottom = 20
... etc
Why is the result type of an assignment Unit
and 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:
val a, b, c = X
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With