Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static initializer is impossible. #617

Closed
gallandarakhneorg opened this issue Mar 27, 2017 · 1 comment
Closed

Static initializer is impossible. #617

gallandarakhneorg opened this issue Mar 27, 2017 · 1 comment
Assignees
Milestone

Comments

@gallandarakhneorg
Copy link
Member

gallandarakhneorg commented Mar 27, 2017

Static initializer syntax is not allowed. For example, it is not possible to write the SARL equivalent to:

public class Messages extends NLS {
	private static final String BUNDLE_NAME = "io.sarl.eventdispatching.messages"; //$NON-NLS-1$

	public static String BehaviorGuardEvaluator_0;
	public static String BehaviorGuardEvaluator_1;
	public static String BehaviorGuardEvaluatorRegistry_0;

	static {
		// initialize resource bundle
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
	}

	private Messages() {
	}
}
@gallandarakhneorg
Copy link
Member Author

According to the Xtend forum (because the SARL OOP is strongly inspired by Xtend), static initializers should be written with block expressions as initializers.
It example above becomes in SARL:

final class Messages extends NLS {

	private static val BUNDLE_NAME = {
		val name = "io.sarl.eventdispatching.messages"
		// initialize resource bundle
		NLS.initializeMessages(name, typeof(Messages))
		name
	}

	public static var BehaviorGuardEvaluator_0 : String
	public static var BehaviorGuardEvaluator_1 : String
	public static var BehaviorGuardEvaluatorRegistry_0 : String

	private new {
	}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant