Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

RFC, why is there no support for reflection to create version adaptable code?

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.

 

 

http://java.sun.com/docs/books/tutorial/reflect/member/methodInvocation.html

 

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).

 

 

 

 

Thanks.

Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: RFC, why is there no support for reflection to create version adaptable code?

J2ME is based on java 1.4 and BB is based on J2ME. No way to change that.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
Yvon
Posts: 4
Registered: ‎04-20-2010
My Device: 9000
My Carrier: Verizon

Re: RFC, why is there no support for reflection to create version adaptable code?

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.

 

Yvon

Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: RFC, why is there no support for reflection to create version adaptable code?

you can search the forum about combining jad files manually. or use the UpdateJad.exe shipping with jde/ejde
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
Yvon
Posts: 4
Registered: ‎04-20-2010
My Device: 9000
My Carrier: Verizon

Re: RFC, why is there no support for reflection to create version adaptable code?

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.

Please use plain text.
Developer
Developer
mb1
Posts: 318
Registered: ‎05-26-2009
My Device: Not Specified

Re: RFC, why is there no support for reflection to create version adaptable code?

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.

 

http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: RFC, why is there no support for reflection to create version adaptable code?

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.

 

Thinking net_rim_reflect.cod...

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.