views:

327

answers:

1

I found the folliwing code sample in BlackBerry Java Development, Best Practices. Could somebody explain what the below same code means? What is the this in the code sample poining to?

Avoiding StringBuffer.append (StringBuffer)

To append a String buffer to another, a BlackBerry® Java Application should use net.rim.device.api.util.StringUtilities.append( StringBuffer dst, StringBuffer src[, int offset, int length ] ).

Code sample

public synchronized StringBuffer append(Object obj) { if (obj instanceof StringBuffer) {

StringBuffer sb = (StringBuffer)obj;

net.rim.device.api.util.StringUtilities.append( this, sb, 0, sb ) return this;

}

return append(String.valueOf(obj));

}

+1  A: 

It means that the StringBuffer class is not implemented efficiently.
Java Strings are supposed to be immutable, that's what StringBuffer is used for. However, the StringBuffer class you're using is not efficient when using StringBuffer.append() so you need to use net.rim.device.api.util.StringUtilities. That's what the code is doing, encapsulating the use of that class in a new append() method.

slipbull