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
____________________________________________________

Reply via email to