Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

int ---> Object Integer?

Status
Not open for further replies.

duan

Technical User
May 30, 2001
9
GB
Hi, Dear all

Can you help me to sort out this problem?

Here is the pat of my code:

variable me is a hashmap's Entryset.

1. v = ((Integer)me.getValue()).intValue();
2. int x = v++;
3. hm.putValue( (Integer) x );

The error lies in line 3."inconvertible type,required java.lang.Integer"

How can I deal with this? I thought I'v already convert int x to Object Integer. However line 1 did the same thing successfully. Quite confuesd.

thanks
Duan
 
new Integer(x)

...instead of...

(Integer)x

as an int is not an Object but a primitive data type and so cannot be cast into another Object...

Hope this helps
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
you can't cast from a primative to an object. you have to create the Integer object i.e.

hm.putValue( new Integer( x ) );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top