I get the impression that Android supports reflection. But does it really? How sensible would it be to rely on reflection heavily? What's the penalty?
Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use of reflected fields, methods, and constructors to operate on their underlying counterparts, within encapsulation and security restrictions.
Reflection is a set of language and library features that allows you to introspect the structure of your program at runtime.
Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. For example, it's possible for a Java class to obtain the names of all its members and display them.
In computer science, reflective programming or reflection is the ability of a process to examine, introspect, and modify its own structure and behavior.
It is supported, and even recommended in the situation where you want compatibility with multiple versions of the Android OS in one apk
file. This article from the official Android Developers Blog describes how to build an app that requires only some early version of the API, and uses reflection to invoke new APIs if they are available:
Backward compatibility for Android applications
Android supports reflection.
Once you've got a prototype running, you can benchmark and determine your bottlenecks.
If its reflection, then consider trying to cache interfaces and such to make it a one-off cost, rather than continually resolving the same interfaces from the same instances repeatedly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With