---
title: "R8 Optimization: Class Reflection and Forced Inlining"
url: https://daily.dev/posts/r8-optimization-class-reflection-and-forced-inlining-xiy4fj9if
source_url: https://jakewharton.com/r8-optimization-class-reflection-and-forced-inlining
type: article
source: "Jake Wharton"
published: 2026-07-05T07:13:39.866Z
updated: 2026-07-05T07:15:18.539Z
tags: ["java", "android"]
reading_time: 6
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# R8 Optimization: Class Reflection and Forced Inlining

**[Jake Wharton](https://daily.dev/sources/jakewharton)** · 6 min read · 0 upvotes · 0 comments

## Summary

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.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://jakewharton.com/r8-optimization-class-reflection-and-forced-inlining>

---

Tags: [#java](https://daily.dev/tags/java), [#android](https://daily.dev/tags/android)

[View this post on daily.dev](https://daily.dev/posts/r8-optimization-class-reflection-and-forced-inlining-xiy4fj9if)
