This post originated from an RSS feed registered with Java Buzz
by Marc Logemann.
Original Post: we need Reflection in MIDP
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
And we need it fast. There are projects where you can live without reflection at all, but its a nightmare to do Webservice calls from a wireless device without reflection. I am using ksoap for soap calls and of course i need to serialize/deserialize objects.
You end up writing code like this:
public void setProperty(int param, Object obj) {
if (param == 0) {
clubVorgabe = ((Integer) obj).intValue();
} else if (param == 1) {
country = (String) obj;
} else if (param == 2) {
coursePar = ((Integer) obj).intValue();
} else if (param == 3) {
courseRating = ((SoapPrimitive) obj).getName();
[..]
The setProperty method is only the deserialisation part, you will also need a serializer for this object which looks similar. When you have 4 attributes, this is ok, but in my project, i have objects with 30 and more attributes. You cant feel your fingers anymore when you are done with one object.
Plus, we have another problem. Object size does matter in the mobile world. Some phones even have restriction how big an object can be at a maximum on the heap. Can you tell me how i should write slim objects without reflection?
So how about a light implementation of the reflection API, i only need JavaBean Style reflection things like discovering the type and calling methods. I know that this wont be very fast on these devices, but hell, the actual coding practice cant be the end.
Perhaps its time to check the Webservice JSR for mobile devices again, wondering how they do (de)serialisation. Most likely its again up to the user to write code like mentioned above.