Thread: Object to Int
View Single Post
Old Nov 28th, 2007, 4:26 PM   #4
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 80
Rep Power: 1 null_ptr0 is on a distinguished road
Re: Object to Int

Object is, haha, an object type, while int is a primitive type. You cannot translate objects to ints through direct casts; but if the object is of Integer, you could access and call the member method intValue() which returns the actual integer value being wrapped.
Example:
public void A(Object o) {
   if(o instanceof Integer)
	B(((Integer) o).intValue());
   else
	throw new IllegalArgumentException();
}

public void B(int i) {
    /*
        code is here
    */
}
__________________
iload_0 iconst_1 ishl or
iload_0 iconst_2 idiv or
iload_0 iconst_2 iconst_1 imul idiv
[1] & [2] use the smallest stack size
null_ptr0 is offline   Reply With Quote