Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for @LazyClassKey. #4252

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions dev-guide/multibindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,23 @@ interface MyComponent {
Your annotation's single member can be any valid annotation member type except
for arrays, and can have any name.

### Lazy class loading

Using `@ClassKey` or a custom annotation with a `Class` type for the annotation
member, allows you to inject a class keyed map. One issue with this approach is
that all the classes in the key set will be loaded when constructing the map.
Depending on the size of the map, this may cause performance problems in
environments like Android. To avoid the unnecessary class loading,
`@LazyClassKey` can be used to generate a string keyed map under the hood,
so that classes are only loaded when used for a lookup.

The `@LazyClassKey` map does not support returning `keySet()` or `entrySet()` as
they will load all class keys and degrade the benefit of using the annotation.
Usage of unqualified `@LazyClassKey` cannot co-exist with `@ClassKey`. This
feature works by using the class names, and so is paired with configuration for
R8 and Proguard. In Proguard, the names of classes used as keys will be kept as
a result of this feature.

### Complex map keys

If your map's key is more than can be expressed by a single annotation member,
Expand Down
Loading