BASE-4618: Update class variable example

This commit is contained in:
Daniel Strmecki 2021-02-21 11:18:05 +01:00
parent 78a8d0bc77
commit 8d8e1b43ca
2 changed files with 18 additions and 26 deletions

View File

@ -1,23 +1,19 @@
package com.baeldung.finalkeyword;
import java.io.Console;
public class ClassVariableFinal {
final static String X = "x";
final static String Y = "y";
static final boolean doX = false;
static final boolean doY = true;
public static void main(String[] args) {
for (int i = 0; i < 1500; i++) {
long startTime = System.nanoTime();
String result = concatStrings();
long totalTime = System.nanoTime() - startTime;
if (i >= 500) {
System.out.println(totalTime);
}
Console console = System.console();
if (doX) {
console.writer().println("x");
} else if (doY) {
console.writer().println("y");
}
}
private static String concatStrings() {
return X + Y;
}
}

View File

@ -1,23 +1,19 @@
package com.baeldung.finalkeyword;
import java.io.Console;
public class ClassVariableNonFinal {
static String x = "x";
static String y = "y";
static boolean doX = false;
static boolean doY = true;
public static void main(String[] args) {
for (int i = 0; i < 1500; i++) {
long startTime = System.nanoTime();
String result = concatStrings();
long totalTime = System.nanoTime() - startTime;
if (i >= 500) {
System.out.println(totalTime);
}
Console console = System.console();
if (doX) {
console.writer().println("x");
} else if (doY) {
console.writer().println("y");
}
}
private static String concatStrings() {
return x + y;
}
}