Discussion Board
Go to the previous messageThere are no next messages
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.
Post response

Go to the previous messageThere are no next messages
Current Thread Detail:
cast an Object to an int or char      Shi, Ying      Fri Sep 28 2001 1:22 am       
Re: cast an Object to an int or ...      Lee, Peter      Fri Sep 28 2001 9:52 am       

Back to previous screen