Java

14 Jun

If you make an ArrayList of a certain type of Object and then try to convert it back to the Object type, you can run into ClassCast Exceptions.

 e.g. 

ArrayList  test = new ArrayList();

MyObject mine = new MyObject;

test.add(mine);

 To get the array of the MyObjects you need to do:

(MyObject[]) test.toArray(new MyObject[test.size()]) 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: