所以,我的理解是:
我该如何解决这个问题?
class BlahBlah
{
public BlahBlah()
{
things = new ArrayList<Thing>();
}
public Thing[] getThings()
{
return (Thing[]) things.toArray();
}
private ArrayList<Thing> things;
}
在另一个班级中,我学到了:
for (Thing thing : someInstanceOfBlahBlah.getThings())
{
// some irrelevant code
}
错误信息为:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LsomePackage.Thing;
at somePackage.Blahblah.getThings(Blahblah.java:10)
我该如何解决这个问题?