How to detect initialization order of fields? [message #1794235] |
Mon, 27 August 2018 15:03  |
Eclipse User |
|
|
|
Hi, I have a testing class like it
class Test {
private Container c1 = new Container(this.c2);
private Container c2 = new Container();
}
In the provided example c2 should be initialized before c1 (doesn't matter of their declaration order), but are there any default Eclipse JDT methods/APIs that can provide me that order? Or such order doesn't exists, but it's created in runtime (e.g. c1 is being initialized, but stopped until c2 is initialized)?
|
|
|
|
|
Re: How to detect initialization order of fields? [message #1794279 is a reply to message #1794277] |
Tue, 28 August 2018 08:16   |
Eclipse User |
|
|
|
Sergey Toshin wrote on Tue, 28 August 2018 14:11Thanks, but it's description how it should work anywhere, but not how it really works in Eclipse.
What exactly is not working that way in Eclipse?
Do we generate wrong byte code?
Quote:
I'm using Eclipse JDT in my own project, and I have FieldDeclaration[] for a class, so I want to resolve order of initializations
Are you interested in the correct order according to JLS (textual source code order), or the semantically meaningful order (with no dereference before initialization)?
As mentioned, when saying "this.c2" this is not guaranteed to be the same order, but when saying "c2", differences between both orders will raise a compile error.
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04857 seconds