Thursday, July 8, 2010

Achieve the Reflection in j2me

Hi

We can not use the Reflection in j2me as we use in j2se because it unavailable in j2me.So how can we achieve it i could workaround & found some Solution

First

add the class name in the build .xml to unobfuscate the class name if we cant so class.forName could not recognize the class name .
jsut add the


then make the interface(FormNameInterfacae) & take the full class name as String(class1) & use that string to get the instance of the class

then take interface (dispalyInfo) that contain the Hashtable that contain its getter & setter

class1 extend the displayInfo interface to share the data between the screens by using the hashtable get & set method

then take another inteface(DisplayInterfacae) that have the function(getObject) that return Displayable Object & it also extend the (displayInfo) interface


Now use should implement the getObject method of (DisplayInterface) in class1 that return displayable object .

Now cast that class instance to that inteface Object Like that

DisplayInterfacae displayInterface=(DisplayInterfacae)class.forName(FormNameInterfacae.class1);


& display the form as calling getObject Method like that

Display display=Display.getDisplay(this);
display.setCurrent(displayInterface.getObject());


It will show the class1 getdisplay method & show the displayble Object you return in class1.

No comments:

Post a Comment