This does indeed not make any sense. If it were a compile time constant which you don't need to massage back to a String
, then it would make a bit more sense. You still have the character encoding problem.
It would make more sense to me if it were a char[]
constant. In real world there are several JSP compilers which optimizes String constants away into a char[]
which in turn can easily be written to a Writer#write(char[])
. This is finally "slightly" more efficient, but those little bits counts a lot in large and heavily used applications like Google Search and so on.
Tomcat's JSP compiler Jasper does this as well. Check the genStringAsCharArray
setting. It does then like so
static final char[] text1 = "some static text".toCharArray();
instead of
static final String text1 = "some static text";
which ends up with less overhead. It doesn't need a whole String
instance around those characters.