This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hey Guys, I am building an ArrayList of DataInfo objects. Then, when I return I want to cast it back to an array of DataInfo objects. So this sample code (very rough):
Now this compiles fine, but at runtime you get a class case exception, saying that returnTest is returning an object. Can someone please explain to me why this is happening, because my casting should be correct, but obviously their is something strange I am missing. Thanks,
just do that (DataInfo) x.toArray(new DataInfo[x.size()]);
Joined: Feb 24, 2002
Cedric, Thank's a lot that snippet worked great, but I am curious as to why it worked. Can you explain what is happening, because it seems slightly redundant to me, but at the same time it works your way and it doesn't my why, I am just curious as to the logic behind it. Thanks again,
Joined: May 22, 2002
Have a look in the JDK API, it's nicely explained -> java.util.ArrayList , public Object toArray(Object a)