Search code examples
javacstringbuilderkvmcldcstringbuffer

How to force use of StringBuffer instead of StringBuilder by default in javac?


I am trying to compile the CLDC with kvm on linux, I get an error

cannot access java.lang.StringBuilder class file for java.lang.StringBuilder not found

at the statement:

return getClass().getName() + "@" + Integer.toHexString(hashCode());

I think that is because this uses its own bootclasspath which contains StringBuffer but not StringBuilder. Now, how do I force javac to use StringBuffer instead of default StringBuilder?

My dev environment is: Ubuntu 10.04.2 LTS + javac 1.6.0_24 (sun-java6-jdk)


Solution

  • After googling around a bit more, I found that one can set the target jsr specification with '-target' option to javac. To fix my problem , I had to go back to jsr14 to emit StringBuffer instead of StringBuilder.

    javac -target jsr14 *.java

    More about this here: http://twit88.com/blog/2008/08/26/java-understanding-jsr14/