Re: Why?
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 10/30/03
- Next message: Roedy Green: "Re: Why?"
- Previous message: Toro: "Re: a question about thread"
- In reply to: Fu, Ren-Li: "Why?"
- Next in thread: Mark Haase: "Re: Why?"
- Reply: Mark Haase: "Re: Why?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Oct 2003 05:43:22 GMT
Ren-Li,
"Fu, Ren-Li" <frl8@rogers.com> wrote in message
news:ZJ0ob.59379$7B1.18226@news04.bloor.is.net.cable.rogers.com...
>
> String s;
> Int i;
>
> s = i; // does not work
>
's' is a 'String' type, while 'i' is an 'int' type [a spelling error in the
original code ? Also, 'i' needs to be initialised before use]. It should be
obvious that an attempt to assign an 'int' type to a 'String' type is
syntactically incorrect since there is no implicit conversion of 'int' type
to 'String' type in Java.
On the other hand, this:
>
> s = "" + i; // works
>
> why doesent it just work with "="? This makes no real sense to me.
>
is ok because some behind-the-scenes 'trickery' see the entire expression
converted to a 'String' type. The following expression is what the above
expression is actually implemented as:
s = new StringBuffer().append("").append(i).toString();
More information can be obtained from the Sun tutorials and documentation.
I hope this helps.
Anthony Borla
- Next message: Roedy Green: "Re: Why?"
- Previous message: Toro: "Re: a question about thread"
- In reply to: Fu, Ren-Li: "Why?"
- Next in thread: Mark Haase: "Re: Why?"
- Reply: Mark Haase: "Re: Why?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|