copile java 1.5 code
Chris Gray
chris.gray@kiffer.be
Wed Jan 26 17:40:00 GMT 2005
On Wednesday 26 January 2005 17:22, Andrew John Hughes wrote:
> [...]Test2 uses the concatenation operator, '+', which requires the
> existence of java.lang.StringBuilder, as 1.5 compilers use this new
> class to perform this operation. This is in GNU Classpath, so you can
> either wait for it to be merged to gcj, or, alternatively, alter the
> class to perform concatenation differently (for example, explicitly
> using java.lang.StringBuffer).
As Oli is quite new, I'll expand on this:gcj uses the java libraries developed
by the Classpath project, but after a short delay (they have to test
everything first). The class java.lang.StringBuilder is already implemented
in the Classpath project, so it will probably be added to the gcj libraries
soon; until then, you can try to use the older class String buffer instead,
e.g. instead of
String s = foo + bar;
you write
StringBuffer sb = new StringBuffer();
sb.append(foo);
sb.append(bar);
String s = sb.toString();
This generates exactly the same bytecode as compilers < 1.5 used to generate
(a 1.5 compiler generates similar code, but s/StringBuffer/StringBuilder/g).
Chris
More information about the Java
mailing list