File tree Expand file tree Collapse file tree 2 files changed +18
-26
lines changed
core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword Expand file tree Collapse file tree 2 files changed +18
-26
lines changed Original file line number Diff line number Diff line change 11package com .baeldung .finalkeyword ;
22
3+ import java .io .Console ;
4+
35public 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}
Original file line number Diff line number Diff line change 11package com .baeldung .finalkeyword ;
22
3+ import java .io .Console ;
4+
35public 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}
You can’t perform that action at this time.
0 commit comments