class in class kann nich serialisiert werden?



  • hi

    wollte vorhin eine klasse in einer klasse (ich bin pseudoordnungsliebend) serialisieren...

    musste sie aber schließ und endlich rausnehmen, dann gings mit dem ohjectstream.

    vorher wollte er die gleiche nicht serialisieren.

    warum?

    ist nicht ganz wichtig, es funzt ja.. hat mich ob meiner struktur und ordnungsliebe eben geärgert...



  • Hi elise,

    in der Java Object Serialization Specification (click) steht dazu:

    Note - Serialization of inner classes (i.e., nested classes that are not static member classes), including local and anonymous classes, is strongly discouraged for several reasons. Because inner classes declared in non-static contexts contain implicit non-transient references to enclosing class instances, serializing such an inner class instance will result in serialization of its associated outer class instance as well. Synthetic fields generated by javac (or other JavaTM compilers) to implement inner classes are implementation dependent and may vary between compilers; differences in such fields can disrupt compatibility as well as result in conflicting default serialVersionUID values. The names assigned to local and anonymous inner classes are also implementation dependent and may differ between compilers. Since inner classes cannot declare static members other than compile-time constant fields, they cannot use the serialPersistentFields mechanism to designate serializable fields. Finally, because inner classes associated with outer instances do not have zero-argument constructors (constructors of such inner classes implicitly accept the enclosing instance as a prepended parameter), they cannot implement Externalizable. None of the issues listed above, however, apply to static member classes.



  • thanks... 🙂


Anmelden zum Antworten