I will explain my problem as clearly and clearly as possible. I think that whatever I am trying may be wrong in nature, but in some way I believe that he should work. So please do not hesitate to treat this post as a mere explanation of the serialization system.
Therefore, I have an interface that has been implemented by a class [it is contained in different files].
// ----- SomeInterface.java Public Interface Some interfaces serializable (Public Zero Set Message (String msg); Public Zero Print Message ();} // ----- SomeImpl.java Public Squares SomeImpl Some Interface {Private String msg; Public Zero Set Message (String msg) {this.msg = msg;} Public Zero Print Message () {System.out.println ("Message:" + msg) ;}} Now I can serial an example of some [...] SomeImpl [/ tt] class:
... public void SomeMethInSomeClass () {FileOutputStream fos = no FileOutputStream (New file ("c: /test.ser"); ObjectOutputStream OOS = New object overputstream (fos); Some interface = new iIPL (); Si.setMsg ("Blow Blow"); oos.writeObject (test) ; Oos.close (); fos.close (); System.out.println ("------ task -------");} now In a separate project, I have a jar of application that has the interface SomeInterface but not the implementation class SomeImpl . If I try to do the following in this application:
.... .... public zero deserialiserMethod () throws an exception {fileInputStream fis = new FileInputStream (new file ("c : / Test.ser ")); ObjectInputStream OIS = New ObjectInstream (FIS); Some interface C = faucet; System.out.println ("------ reading ----------"); C = (some interface) ois.readObject (); Si.printMsg (); System.out.println ("------- done ----------"); Ois.close (); Fis.close (); } .... ... I get a classnotout exception for [codeImgimImpl ]. Now I know that in my other project there is no SomeImpl class in its classpath. But should not be casting in the context of the original interface, take care of that dependency?
It is not a question of casting, it is a class type question of serialized object. It does not matter if your code is ever SomeImpl does not directly reference the class, the fact is that the serial object is still of that type.
Consider this - what class would be an example of the Deserialized object, if not then SomeImpl ? The field has to be defined somewhere, and if SomeImpl is not in, then where?
Even if you want to disassemble the object and put it in java.lang then object , you have the same problem with the real problem and runtime object.
Comments
Post a Comment