Re: Strings odd one out
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 02/21/05
- Next message: Antti S. Brax: "Re: session timeout doesn't work"
- Previous message: google_at_changent.com: "Re: HTML & Java"
- In reply to: jk: "Strings odd one out"
- Next in thread: Tilman Bohn: "Re: Strings odd one out"
- Reply: Tilman Bohn: "Re: Strings odd one out"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Feb 2005 11:14:36 -0500
jk wrote:
> Hi:
>
> My understanding of classes is that a class serves as a wrapper for
> a data, and the operations that can be performed on the given data.
> This is not a very specific definition, but is the motivation for
> my question. The instances of classes are called by their handle.
>
> For instance: adding a string to a vector
> Vector v = new Vector();
> v.add("ABC");
>
> Strings are different in that they can be called by
> a handle, or they can be called by a literal String.
>
> eg:
> String s = "ABC";
> int len1 = s.length();
> int len2 = "ABC".length()
>
> So, this seems 'inside out' ...
> The data that should be wrapped by the class
> is used to invoke methods upon itself from
> outside the class.
You are confusing the program with its source code. A Java String
literal is a representation of a full-fledged String instance that works
just like any other String instance when the program runs. It is
impossible for a program to determine at runtime from a String reference
whether or not the referent corresponds to a String literal in the Java
source.
As for why Java does it this way, consider the question of practicality:
how would you specify the literal contents of a String at compile-time
if you could not use a double-quoted character sequence? If you don't
want to give up the double-quoted character sequence then what could it
represent *other* than a String object?
-- John Bollinger jobollin@indiana.edu
- Next message: Antti S. Brax: "Re: session timeout doesn't work"
- Previous message: google_at_changent.com: "Re: HTML & Java"
- In reply to: jk: "Strings odd one out"
- Next in thread: Tilman Bohn: "Re: Strings odd one out"
- Reply: Tilman Bohn: "Re: Strings odd one out"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|