| Author |
private static final String and concatenation question
|
Edward Winchester
Ranch Hand
Joined: Sep 16, 2009
Posts: 65
|
|
Hello,
If I have a private static final String in a class, and that String was assigned the result of string concatenation, is it defined whether the concatenation occurs at runtime, or compile time?
e.g.
I guess it doesn't really matter because the cost is a one-off initialisation cost, but it was something I was wondering about.
Ed
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16692
|
|
It depends on whether the expression (concat) is a compile time constant or not.
In this case, it is, and hence, the concat occurs at compile time. In fact, since you are assigning it to a final variable at declare time, the static variable is a compile time constant variable. This means that it can be used in another expression, with other constants, and it will still be a compile time constant expression.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Edward Winchester
Ranch Hand
Joined: Sep 16, 2009
Posts: 65
|
|
|
Thank you Henry.
|
 |
 |
|
|
subject: private static final String and concatenation question
|
|
|