3 ms·
That Iterator Again
- RodgerTheGreat 17y agoUsing reflection really hamstrings the JVM JIT- This stack overflow thread corroborates the "factor of ten" figure, in this case for object instantiation: http://stackoverflow.com/questions/435553/java-reflection-performance http://stackoverflow.com/questions/435553/java-reflection-pe...
- jimbokun 17y agoMore like this please. I really like Bray's style of trying something, posting it on the Internet, letting the Internet tell him how he is doing everything wrong, then summarizing the responses about how to do it right (or explain why he's going to continue to do it wrong, like in this case where for his case the performance impact just doesn't matter). His Wide Finder series followed the same formula. With regard to the content, I like to use reflection when I'm marshalling objects into and out of some serialization format. The most recent example is marshalling Java-Beanish objects into JSON in response to AJAX calls. I figure with the overhead of serializing everything to a String, and pushing those bytes across a network, the reflection hit won't be perceptible. I also like Jerome Lacoste's solution keeping the Iterator interface but dumping the reflection. http://github.com/lacostej/android-providerhelper/ http://github.com/lacostej/android-providerhelper/ "We get almost best of both world: * good performance (almost no reflection) * code easy to read."