RE: Integer vs. Number vs int
RE: Integer vs. Number vs int
- Subject: RE: Integer vs. Number vs int
- From: "Pierre Bernard" <email@hidden>
- Date: Thu, 27 Nov 2003 16:44:12 +0100
- Thread-topic: Integer vs. Number vs int
BTW,
there is a major difference between those two lines of code:
public int tempNum = 1;
public String tempString = "abc";
The first one creates a primitive type. The second one creates an object: an instance of java.lang.String. Indeed "abc" is a handy shortcut to create a String object. It might be confusing at first sight as it makes String look like it was a primitive type. But it sure is much more convenient than new String(new char[] { 'a', 'b', 'c' }), isn't it?
Pierre
-----Original Message-----
From: Pierre Bernard
Sent: Thursday, November 27, 2003 4:02 PM
To: Drew Thoeni; email@hidden
Subject: RE: Integer vs. Number vs int
Hi!
The number 1 is an int. int is a primitive type. Other primitive types are: long, double, float, char, boolean, ...
Along those primitive types Java has corresponding wrapper objects that provide a ceratin number of utility methods. The main reason for their existence is for the programmer to be able to handle and store such types the same way as any other Java object. E.g. the only way to store a number in a collection is by wrapping it in such an object. Examples are Integer, Long, Char, Boolean ...
Your variable is a reference to an object of type Number. Number is an abstract superclass of the various wrapper object that represent numbers. You may assign any instance of a concrete subclass of Number to your variable. Integer is such a class. new Integer(1) is a matching object.
For further reading I suggest Bruce Eckel's Thinking in Java. A link to it is available from my web page: http://homepage.mac.com/I_love_my/webobjects.html
Pierre.
-----Original Message-----
From: Drew Thoeni [mailto:email@hidden]
Sent: Thursday, November 27, 2003 12:09 PM
To: email@hidden
Subject: Integer vs. Number vs int
I am trying to put a numeric value into an Number object using:
public Number tempNum = 1;
But I get "incompatible types" on compile.
I'm new to Java but this seems analogous to the Java
public String tempString = "abc";
Which compiles fine.
I get the same "incompatible types" with:
public Integer tempNum = 1;
What am I missing?
Drew
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender
of this message. (email@hidden)
This email message has been checked for the presence of computer
viruses; however this protection does not ensure this message is
virus free.
Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
**********************************************************************
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender
of this message. (email@hidden)
This email message has been checked for the presence of computer
viruses; however this protection does not ensure this message is
virus free.
Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
**********************************************************************
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.