R8, Android's optimizer, can replace runtime reflection calls like `getClass().getSimpleName()` with compile-time string constants through whole-program analysis. When R8 determines a class has no subtypes, it substitutes `getClass()` with a class literal, then chains that into existing class constant optimizations to produce a plain string. For cases where the class isn't directly known at the call site — such as a library method accepting an Activity — the undocumented `-alwaysinline` directive can force inlining of the method body into each call site, making the class known at compile time and enabling the full optimization chain. The post warns that `-alwaysinline` is unsupported and may change; Kotlin's `inline` modifier is the stable alternative for Kotlin callers.

6m read timeFrom jakewharton.com
Post cover image
Table of contents
Instance reflectionInlining by force