Guillaume Cottenceau wrote:
> Paul, all,
> I can read in chapter 1:
> // StringBuffer is immutable
Oops, that's a typo. It should read StringBuffer is mutable.
Sorry, must have cut and pasted the String comment and only half
fixed it up. Want me to submit a patch or can you fix it?
> Being myself a java programmer (but an ignorant of groovy), I
> found it weird to read that StringBuffer would be immutable in
> groovy. Actually, a quick test seems to prove otherwise:
> [gc@... /tmp/groovy-1.0] ./bin/groovy -e 'sb = new StringBuffer("hello"); print sb + "\n"; sb.append(" world"); print sb + "\n";'
> hello world
> Did I miss something?
> Btw, do you know why we need to write:
> assert sb.toString() == 'hibiscus'
> I mean, in java, String equality needs #equals; so if groovy is
> nice enough to provide == equality for String objects, why not
> doing another effort and providing the same for StringBuffer
> objects so that we can write "sb == 'hibiscus'"?
That would probably make an interesting addition. I'll propose it
to the Groovy dev list.
There is an ongoing debate though about equals and different
types. If you read the Java guidelines for equals and compareTo
then by the letter of the law different object types should
always return false with equals. Groovy breaks this in a small
number of places, e.g. Long == Integer. Perhaps this is a
case which should also be handled differently.
> Btw, I have been unable to find an API reference for using
> groovy? (e.g. all classes and methods available in groovy, as
> there are more things than in java, e.g. String#each for example,
> etc) Is there one? http://groovy.codehaus.org/apidocs/ seems to
> be the javadoc of the groovy language itself. (Btw, is groovy
> written entirely in java?)
Groovy is written in Java and Groovy.
Re doco, I think what you want is: