Skip to content

Commit 9b25dca

Browse files
committed
BASE-4618: Update class variable example
1 parent ab985de commit 9b25dca

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package com.baeldung.finalkeyword;
22

3+
import java.io.Console;
4+
35
public class ClassVariableFinal {
46

5-
final static String X = "x";
6-
final static String Y = "y";
7+
static final boolean doX = false;
8+
static final boolean doY = true;
79

810
public static void main(String[] args) {
9-
for (int i = 0; i < 1500; i++) {
10-
long startTime = System.nanoTime();
11-
String result = concatStrings();
12-
long totalTime = System.nanoTime() - startTime;
13-
if (i >= 500) {
14-
System.out.println(totalTime);
15-
}
11+
Console console = System.console();
12+
if (doX) {
13+
console.writer().println("x");
14+
} else if (doY) {
15+
console.writer().println("y");
1616
}
1717
}
1818

19-
private static String concatStrings() {
20-
return X + Y;
21-
}
22-
2319
}
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package com.baeldung.finalkeyword;
22

3+
import java.io.Console;
4+
35
public class ClassVariableNonFinal {
46

5-
static String x = "x";
6-
static String y = "y";
7+
static boolean doX = false;
8+
static boolean doY = true;
79

810
public static void main(String[] args) {
9-
for (int i = 0; i < 1500; i++) {
10-
long startTime = System.nanoTime();
11-
String result = concatStrings();
12-
long totalTime = System.nanoTime() - startTime;
13-
if (i >= 500) {
14-
System.out.println(totalTime);
15-
}
11+
Console console = System.console();
12+
if (doX) {
13+
console.writer().println("x");
14+
} else if (doY) {
15+
console.writer().println("y");
1616
}
1717
}
1818

19-
private static String concatStrings() {
20-
return x + y;
21-
}
22-
2319
}

0 commit comments

Comments
 (0)