how to change the class type ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Sonia

how to change the class type ?

Post by Sonia » Sun Jan 05, 2003 6:56 pm

Hello,

I want to ask how to change the an object class type to XYDataset type ?

i.e. I want to make the XYDataset data reference to Object obj,

Thanks for telling me

:)

David Gilbert

Re: how to change the class type ?

Post by David Gilbert » Tue Jan 07, 2003 12:10 pm

You can cast an Object to an XYDataset using:

XYDataset data = (XYDataset) obj;

...but you will get an exception if obj doesn't implement the XYDataset interface, so you might want to check first:

XYDataset data = null;
if (obj instanceof XYDataset) {
data = (XYDataset) obj;
}

if (data != null) {
// do something...
}

Regards,

Dave Gilbert

Locked