Search code examples
javaandroidperformancereflectionparceler

Does Parceler library use reflection?


In the description of the library, you can read that it uses code generation. A bit further you can read this:

Be careful not to use private fields when using the default field serialization strategy as it will incur a performance penalty due to reflection.

Now that confuses me! Does it use reflection or code generation. And if it does use reflection, I don't see the point of such library since the whole point of Parcelables is to avoid Serializables that use reflection?


Solution

  • Parceler generates Parcelable wrappers for you code which allows you to avoid writing the boilerplate. One advantage of this is the high performance of static compiled code. In certain circumstances, like with accessing private fields, methods or constructors, Parceler has to resort to using reflection which, as the referenced note mentions, will cause a warning to be issued.

    So, in short, Parceler largely uses code generation to handle writing Parcelable boilerplate, but will resort to reflection is some cases.