|
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.
____________________________________________________ To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm Be respectful! Clean up your posts before replying ____________________________________________________ |
- [jdjlist] Re: package and CLASSPATH Kola Oyedeji
- [jdjlist] Re: package and CLASSPATH Roger Glover
- [jdjlist] Re: package and CLASSPATH Rick Alsopp
- [jdjlist] Re: package and CLASSPATH Rick Alsopp
- [jdjlist] String and other classes Lambok Sianturi
- Scot Mcphee
