-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74ec18e
commit daf6dee
Showing
22 changed files
with
237 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
public class StaticInitializationAdvanced { | ||
public static void main(String[] args) { | ||
int classCWithHelperNonStaticGetter = ClassC.staticField; | ||
|
||
int classDWithHelperStaticGetter = ClassD.staticField; | ||
|
||
ClassC.staticField = 600; | ||
int classCIsModified = ClassC.staticField; | ||
|
||
int classEAsSumOfCAndD = ClassE.staticField; | ||
|
||
int result = classCWithHelperNonStaticGetter + classDWithHelperStaticGetter * classCIsModified / classEAsSumOfCAndD; | ||
} | ||
} | ||
|
||
class ClassC { | ||
static Helper helper; | ||
static int staticField; | ||
|
||
static { | ||
helper = new Helper(500); | ||
staticField = 150 + helper.calculateNonStaticFieldValue(); | ||
} | ||
} | ||
|
||
class ClassD { | ||
static int staticField; | ||
|
||
static { | ||
staticField = Helper.calculateStaticFieldValue(); | ||
} | ||
} | ||
|
||
class ClassE { | ||
static int staticField; | ||
|
||
static { | ||
staticField = ClassC.staticField + ClassD.staticField; | ||
} | ||
} | ||
|
||
class Helper { | ||
private final int value; | ||
|
||
Helper(int value) { | ||
this.value = value; | ||
} | ||
|
||
static int calculateStaticFieldValue() { | ||
return 250; | ||
} | ||
|
||
public int calculateNonStaticFieldValue() { | ||
return value; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
|
||
public class StaticInitializationCircular { | ||
public static void main(String[] args) { | ||
int classA = ClassACircular.staticField; | ||
int classB = ClassBCircular.staticField; | ||
int result = classA + classB; | ||
} | ||
} | ||
|
||
class ClassACircular { | ||
static int staticField; | ||
|
||
static { | ||
staticField = 100 + ClassBCircular.staticField; | ||
} | ||
} | ||
|
||
class ClassBCircular { | ||
static int staticField; | ||
|
||
static { | ||
staticField = 300 + ClassACircular.staticField; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
|
||
public class StaticInitializationWithinOneClass { | ||
static int staticField; | ||
|
||
static { | ||
int xxx = 1337; | ||
staticField = xxx; | ||
} | ||
|
||
public static void main(String[] args) { | ||
staticField = 100; | ||
int result = staticField; | ||
} | ||
} |
Oops, something went wrong.