Re: Why?

From: Anthony Borla (ajborla_at_bigpond.com)
Date: 10/30/03


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



Relevant Pages

  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • RE: Controling Modal Dialogs (Solution)
    ... doesn't return until the 'modal' browser returns. ... string varOptions) ... public void DocumentComplete ... int rc = winDisp.Invoke(rgDispId, ref guid, 0, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Gcc compatible header file
    ... A string collection is a table of zero terminated strings that will grow ... typedef struct _StringCollection StringCollection; ... int; ... bool; ...
    (comp.lang.c)
  • Kernighan and Pikes "Beautiful" Code
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • Re: FTP CD command
    ... public const int GENERIC_WRITE = 0x40000000; ... string lpszProxyName, ... public static extern IntPtr InternetConnect ( ... public static extern bool FtpGetCurrentDirectory ( ...
    (microsoft.public.dotnet.languages.vb)