BASE-4618: Class variable example

This commit is contained in:
Daniel Strmecki 2021-02-20 18:13:18 +01:00
parent 6733ed715b
commit 78a8d0bc77
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package com.baeldung.finalkeyword;
public class ClassVariableFinal {
final static String X = "x";
final static String Y = "y";
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);
}
}
}
private static String concatStrings() {
return X + Y;
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.finalkeyword;
public class ClassVariableNonFinal {
static String x = "x";
static String y = "y";
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);
}
}
}
private static String concatStrings() {
return x + y;
}
}