T
Thomas Hawtin
I am part of a small J2ME projekt that has both a server side (J2EE)
and a client side (J2ME, MIDP 1.0). Now I have found a small problem,
when we share code on both sides. I have an class Article, which is
needed on both the mobile phone application, and on the server side.
Now, on the server side I need it to be serializable, but when I write
"implements java.io.Serializable" it won't compile on the client side
(using Sun's Wireless Toolkit). Apperently the interface
java.io.Serializable doesn't exist in in MIDP 1.0. To work around this,
we currently have two different Article classes, one for each side. But
it feels really stupid to have two practically identical classes. The
*ONLY* difference is that one implements java.io.Serializable. Is there
a better way? We would like to use a single class file for both sides.
The technique I've used is to use my own interface xyz.Serializable
instead of java.io.Serializable. The version of xyz.Serializable
compiled for J2SE/J2EE implements java.io.Serializable. The J2ME version
does not.
Alternatively you can use sed or something similar (there's a suitable
task in ANT) to remove the implements java.io.Serializable when
compiling for J2ME. Or equivalently, to add it when compiling for J2SE/J2EE.
First I thought that we could simple create the package java.io on the
J2ME side, with the interface Serializable. But what would happen if
the application is run on a MIDP 2.0 phone, that already has the
java.io.Serializable interface? It seems that it could cause some
trouble...
If the phone already has java.io.Serializable, then it will just use its
own copy. However, if it doesn't have it, then it will probably complain
about loading classes into java.*.
Tom Hawtin