09-17-2008 10:30 AM
This is just a general request for comment or opinion on making code version-adaptable at run time
and the suitability for reflection for accomplishing this.
Perhaps it would be better suited for sun or a jcp board but I am curious if this has been considered by rim
or jcp for j2me as it would seem to be an ideal and reasonably easy thing to implement. You can test
for the existence of a given method or class and invoke it by name if it is available. This would eliminate
a lot of trivial version specific source code modifications but I guess it could create security issues.
This came up most recently when I wanted to use something like CoverageInfo when the class if available but didn't
want to create a whole new version for this feature. With conditional compilation or if you are already forced to
make version specific code it isn't a big deal but probably many version specific builds could be avoided by
building with the least recent JDE that supports reflection ( if any did of course).
09-17-2008 10:32 AM
04-21-2010 05:31 PM
I've experimented with creating 3 COD files.
1. The main.cod which contains the common code
2. The interface.cod which contains interfaces to OS specific implementation classes
3. The implemenation.cod which contains calls to APIs only supported in more recent OSes
2 and 3 are libraries. And 1 uses Class.fromName() to access and create instance of the classes in 3 but only if the OS is known to support the features implemented in that class (e.g. VirtualKeyboard in 4.7).
The use of a shared interface.cod avoids the needs for reflection.
This appears to work in JDE 4.7 with 4.6 and 4.7 simulators.The 4.6 simulator is happy to load main.cod and run the app (no exceptions from the linker at load time). And the 4.7 simulator is happy to instantiate the classes in implementation.cod and call the APIs only available in 4.7.
The advantage is that I can build one core COD for all platforms. The disadvantage is that I have to create 3 CODs total (but only once). And in the future if I want to take advantage of an even newer API, I'll have to create a 4th COD to implement those classes.
I now have to figure out how to configure the JAD so that OTA will download all three CODs and run! And then test on real devices... Helpful hints welcomed.
04-22-2010 03:56 AM
04-22-2010 11:17 AM
Yes! I used the updatejad.exe utility to easily combine the JAD files for the 3 pieces and downloaded all CODs from one JAD file onto my phone. So the above solution appears to work.
04-22-2010 03:39 PM
Good point. Reflection support would allow us to leverage the APIs in newer versions without using ifdef pragmas.
Its supported in competing Android platform to address the backward compatibility issues.
04-22-2010 05:02 PM
I would love for BlackBerry to have reflection, not so much for Backwards/Forwards compatibility (reflection even on a desktop is very performance intensive) but because it makes it easier to choose what function to use based on what the user wants.