java - 2 Classes implements same Interface --> Throw ClassCastException -
i have 2 classes implements same interface called iprocess.
iprocess.java
bundle org.xxx.module.workflow.bo.interfaces; public interface iprocess extends imasterobject { inode getcurrentnode(); inode getpreviousnode(); long getlastchange(); iworkflow getworkflow(); }
first class
package org.xxx.module.workflow.database.bo.impl; import org.xxx.module.workflow.bo.interfaces.inode; import org.xxx.module.workflow.bo.interfaces.iprocess; import org.xxx.module.workflow.bo.interfaces.iworkflow; import org.xxx.module.workflow.database.jdbc.entity.processentity; public class processentitywrapper implements iprocess { private string id; private inode currentnode; private inode previousnode; private long lastchange; private iworkflow workflow; public processentitywrapper(processentity entity) { this.id = entity.getid(); this.lastchange = entity.getlastchange(); } @override public string getid() { homecoming id; } @override public inode getcurrentnode() { homecoming currentnode; } @override public inode getpreviousnode() { homecoming previousnode; } @override public long getlastchange() { homecoming lastchange; } @override public iworkflow getworkflow() { homecoming workflow; } /** * @param currentnode currentnode set */ public void setcurrentnode(inode currentnode) { this.currentnode = currentnode; } /** * @param prevoiusnode prevoiusnode set */ public void setpreviousnode(inode previousnode) { this.previousnode = previousnode; } /** * @param workflow workflow set */ public void setworkflow(iworkflow workflow) { this.workflow = workflow; }
}
second class:
package org.xxx.module.workflow.bo.impl; import org.xxx.module.workflow.bo.interfaces.inode; import org.xxx.module.workflow.bo.interfaces.iprocess; import org.xxx.module.workflow.bo.interfaces.iworkflow; public class process implements iprocess { public process(string id, inode currentnode, inode previousnode, long lastchange, iworkflow workflow) { this.id = id; this.currentnode = currentnode; this.previousnode = previousnode; this.lastchange = lastchange; this.workflow = workflow; } private string id; private inode currentnode; private inode previousnode; private long lastchange; private iworkflow workflow; @override public string getid() { homecoming id; } @override public inode getcurrentnode() { homecoming currentnode; } @override public inode getpreviousnode() { homecoming previousnode; } @override public long getlastchange() { homecoming lastchange; } @override public iworkflow getworkflow() { homecoming workflow; } /** * @param currentnode currentnode set */ public void setcurrentnode(inode currentnode) { this.currentnode = currentnode; } /** * @param previousnode previousnode set */ public void setpreviousnode(inode previousnode) { this.previousnode = previousnode; } /** * @param lastchange lastchange set */ public void setlastchange(long lastchange) { this.lastchange = lastchange; } }
part, throw classcastexception:
@override public void route(iprocess process, inode nextnode) { if(initializedclient == null) { return; } process processimpl = (process) process; processimpl.setpreviousnode(process.getcurrentnode()); processimpl.setcurrentnode(nextnode); dataaccess.updateprocess(processimpl); }
process processentitywrapper -object , processimpl process object
i don't know, why specific code throws classcastexception. can help me, please?
thanks
edit
@override public void updateprocess(iprocess process) { typedquery<processentity> q = em.createquery(workflowaccessproperties.select_processes_by_id,processentity.class); q.setparameter("id", process.getid()); processentity entity = (processentity) q.getsingleresult(); em.gettransaction().begin(); entity.setlastchange(system.currenttimemillis()); string previousid = null; if(process.getpreviousnode() != null) { previousid = process.getpreviousnode().getid(); } entity.setpreviousnodeid(previousid); entity.setcurrentnodeid(process.getcurrentnode().getid()); em.gettransaction().commit(); }
although processentitywrapper
, process
implements same interface don't extend each other.
they different classes implementing same interface.
any class can implement interface. doesn't mean can converted eachother.
example: cow , bird can implement same interface can't convert cow bird because implement same interface.
public interface speakable(){ public string speak(); } public class cow implements speakable(){ public string speak(){ homecoming "moooo"; } } public class bird implements speakable(){ public string speak(){ homecoming "vik vik"; } }
java interface classloader classcastexception
No comments:
Post a Comment