开发者

In J2ME ,how to invoke/call a method by its name?

开发者 https://www.devze.com 2023-02-22 07:17 出处:网络
Is it possible in J2ME to call/invoke a method by its name.just like we have开发者_Go百科 getDeclaredMethod in java .The java.lang.reflect package is available only in CDC 1.1.2. If you\'re not on suc

Is it possible in J2ME to call/invoke a method by its name.just like we have开发者_Go百科 getDeclaredMethod in java .


The java.lang.reflect package is available only in CDC 1.1.2. If you're not on such configuration, you're out of luck. There is no way to invoke a method by name without reflection.

A workaround would be to create a map from strings (method names) to appropriate classes on which you can invoke the methods.


Closest you can get is to instantiate a class by name using Class.forName("com.class.ClassName").newInstance() -- that will execute a parameterless constructor.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号