Well, yes, Daivd you're right but I wanted to simplify it down to a dichotomy between things of type Object and things that are primitive types. So that's why I chose to use "String" = {'S', 't', 'r', 'i', 'n', 'g'} because ultimately underlying it somewhere that's what is happening. Otherwise we get into this business of the compiler behaviour in terms of implicit constructors "String" is translated to new String("String") which looks recursive (Damn) to me, so I just wanted to head all that explanation off and go straight to the jugular of the char[]. And prevent further loading of the air conditioning. ;-)
 
regs
scot.
 
 
-----Original Message-----
From: Burnett, David [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 6 February 2003 15:05
To: JDJList
Subject: [jdjlist] RE: String and other classes

However "a string" is a String object, so you can get strange constructs like "String".substring(2,6)
or if( "war".equals(bushsPolicy) )  ( where conveniently you don't have to worry about whether bushsPolicy is null :-)
 
Actually that seems to scramble your String str = new String({'S', 't', 'r', 'i', 'n', 'g'}); analogy.
if you do something like
    String str1 = "String";
    String str2 = "String";
The str1 and str2 handles will often point to the same object (depending on how the compiler deals with String literals),
so it's more like the "String" statement is an implicit object constructor and the String str = is just the assigning of a pointer/ handle to it.
 
Airconditioner in this office is currently too hot for thought..........
 
db
-----Original Message-----
From: Scot Mcphee [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 06, 2003 2:25 PM
To: JDJList
Subject: [jdjlist] RE: String and other classes

String str = "String";
 
is a shorthand for
 
String str = new String({'S', 't', 'r', 'i', 'n', 'g'});
 
(An immutable string object constructed from an array of chars). The answer is that for the others they don't work because the compiler designers didn't feel like adding shortcuts for them.
 
Primitive types, of which String is not one, don't inherit from Object and are things like int, byte, boolean char, short, double, float, long, etc. They all have related 'wrapper' classes like Integer, Byte, Char, Boolean and so on which DO inherit from Object.
 
When you type literals like;
 
true
1
2.2222E+3
'c'
 
And so on those things are the PRIMITIVE types, not the object wrapper types.
 
So you are required to use the form;
 
int i = 1;
double d = 2.33;
boolean b = true;
 
If you want the wrapper object you have to construct it fully;
 
Integer i - new Integer(1);
Double d = new Double(2.33);
Boolean b = new Boolean(true);
 
Any basic Java book or tutorial website will have a complete explantion in it's first few chapters.
 
regs
scot.
 
-----Original Message-----
From: Lambok Sianturi [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 6 February 2003 13:21
To: JDJList
Subject: [jdjlist] String and other classes

Hi all,
 
Why if declared
String str = "string";
will be fine but not for 
Number three = 3;
Integer one = 1;
Float flt = 2.2222E+3;
or other classes. It will raise incompatible types.
 
Thanks in advance
 
::Lambok Sianturi::
==(OFFICE BOY)==
PT. Multi Garmenjaya
Jl. Krawang No. 1
Bandung - Jawa Barat
Phone : 62 22 7272222
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to