开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜