Variables are not collected with garbage - there are objects.
"fn" is a string literal, so it will be interned. It will not be garbage collection (at least as long as this ClassLoader is alive, not sure if there is one pool pool on the CL or one for the entire JVM, but it probably doesn't matter), and the same string object will be used for every call.
If you make this a public static ending, there will definitely be an improvement, since concatenation can be performed by the compiler, rather than at run time.
If you make it final in the method (i.e. still as a local variable), this may have the same effect - I'm not sure.
source share