why does reflection slow down android phone

本小妞迷上赌 提交于 2019-12-06 04:03:08
Brian Cooley

Take a look at this question. Basically, you are getting outside of the optimizations that the compiler can perform because reflection happens dynamically.

If you're not making a lot of reflection calls (e.g., it would be bad to do inside the getView of a ListView), you can probably get away with it. It's there to be used, just be judicious about it.

CommonsWare

how true is this?

It is slower than not using reflection. It is definitely something you want to avoid in loops or during rapid UI processing (e.g., scrolling a ListView).

i get some parameters from a web service which have the same name as the parameters of a class i have in my android app. so i just set the values of these parameters using java fields and reflection... it doesn't seem to slow down the performance..

It does, though it may not be noticeable to the user in this case.

can anybody explain to me the fact behind this idea about reflection slowing down performance?

See the link provided by @Brian Cooley in his answer. Bear in mind that reflection on Dalvik (the virtual machine in Android) may be slower than reflection on the Java VM -- I am really rather certain it is not faster, at any rate.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!