Skip to main content

Postinit bind

3 replies [Last post]
jeff_martin
Offline
Joined: 2004-02-03
Points: 0

Anyone know why the following code generates the following error - or a better way to do an attribute bind on instanciation?

public class RectangleX extends Rectangle {
postinit {
anchorX = bind getWidth()/2;
anchorY = bind getHeight()/2;
};
}

Error: Sorry, I was trying to understand an expression but I got confused when I saw "bind" which is a keyword.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jeff_martin
Offline
Joined: 2004-02-03
Points: 0

That didn't work, though it seemed promising. Looking at the docs, it sounds like the "let" keyword might mean something like "final var", meaning once it's declared, you can't reassign it.

I found success with this:

override attribute anchorX = bind getWidth()/2;

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

Your solution is the right one.

Be aware, that "let" (which was renamed to "def" in a later release) does not have the exact same meaning like final var. If you do the following, "a" cannot be reassigned, but it can change its value:

[code]
def a = bind b;
[/code]

shagus
Offline
Joined: 2007-05-10
Points: 0

Hi, use the let keyword.

[code]
public class RectangleX extends Rectangle {
postinit {
let anchorX = bind getWidth()/2;
let anchorY = bind getHeight()/2;
};
}
[/code]