i have piece of code has jdk 1.4 compliant. , below snippet gets runtime exception.
basedocument basedocument = new basedocument(); basedocument.setguid("{somethinghere}"); list document = new arraylist(); document.add(basedocument);//runtime error exception:
java.lang.classcastexception: [ljava.lang.object; incompatible [lcom.company.base.basedocument; i don't understand why cant cast java object(since object parent class of classes in java).
im using ibm jdk version 1.7 eclipse compiler settings set jdk 1.4
please explain mistake i'm doing here. know generics standard, has jdk 1.4 compliant :(
thanks in advance!
actually, message says:
[ljava.lang.object; incompatible [lcom.company.base.basedocument; the [ characters important. apparently, attempting cast of type object[] basedocument[]; i.e. dealing array types here.
however, have no idea causing problem here, because (on face of it) there should no instances of basedocument[] in code have posted. furthermore, don't believe claim that exception thrown @ line. here source code of arraylist.add method (java 6 version):
private transient object[] elementdata; public boolean add(e e) { ensurecapacity(size + 1); // increments modcount!! elementdata[size++] = e; return true; } an assignment of reference object array (object[]) not entail runtime type-checks, , cannot throw classcastexception.
if showed complete stacktrace, easier diagnose.
Comments
Post a Comment