Current Forum: Homework 3 Forum |
Date: Fri Sep 28 2001 9:52 am |
Author: Lee, Peter <petel@cmu.edu> |
Subject: Re: cast an Object to an int or char |
|
|
Suppose x is of type Object. You can cast it to Integer by saying
(Integer)x
Note that this will cause a run-time exception if x is not an instance of class Integer.
Then, to get an int out of this, you can say
((Integer)x).intValue()
The intValue() method extracts the int from an Integer object. |
|