Re: Why String is Immutable?



Tim Tyler <tim@xxxxxxxxxxx> writes:

> That makes a String and then converts is to a StringBuffer

No, it take the interned String in the constant pool and creates a
StringBuffer using that.

> StringBuffer b = "It is clear what this means - but it doesn't compile";

Yes it is, except with a few more characters.

> It's also an example of Java's verbosity. I don't want to tell the
> compiler *twice* that I'm using a StringBuffer on the same line -
> it just makes Java code more painful and boring to read.

Ah, someone who feels C++'s confusing way of creating objects is good.
But in C++, too, you use "new classname()" when creating references.

> ...while being much neater and shorter.

If shortness is your goal, try PL/1 or J.

> Without it we'd be somewhere around: LET two = 1.plus(1);

Readability beats "writability" any day as long as you write something
that is supposed to be maintained later on, perhaps even by someone
else than you.

Do you comment your code? If so, why?
.



Relevant Pages

  • Re: accessing objects in JNI
    ... into the c code from the java code? ... To get to the address field (String) in the MyClass, ... "passing arg 2 of pointer to function from incompatible pointer type" ...
    (comp.lang.java.programmer)
  • How to compile a implementation java script?
    ... I have 2 Java code. ... public interface BookTracker ... public void updateBook(String title, String ASIN, String ISBN, String ... Changing public to abstract let me compile, ...
    (comp.lang.java.programmer)
  • Re: variable scope problem..
    ... Second value: My String ... Instead of asking questions that are accompanied ... Therefore accompany your questions ... with Java code, code that shows what problems you are having. ...
    (comp.lang.java.help)
  • Java Applet Callable by Javascript
    ... I have the following java code that I would like to make into an ... to at minimum turn the following code into an applet.. ... GetMethod method = new GetMethod; ... String contents = method.getResponseBodyAsString; ...
    (comp.lang.java.programmer)
  • Working with String[] and ArrayList
    ... I have a String[] that I need to manipulate ... in Java code. ... I would really prefer to work with an ArrayList to avoid the inevitable out ... of bounds errors and having to grow the array, ...
    (comp.lang.java.programmer)