Annotation Interface OnlyUsedBy


@Documented @Retention(CLASS) @Target(METHOD) public @interface OnlyUsedBy
Marks a component or Hilt @EntryPoint method as only being called by bindings matching the given binding identifiers.

A binding's identifier can be declared with BindingIdentifier. When @BindingIdentifier is not specified, an @Inject constructor binding defaults to its own class as its identifier; other bindings have no default identifier.

If none of the listed binding identifiers are reachable in the binding graph, Dagger prunes the annotated method and its exclusive transitive dependencies before validation and code generation. Invoking a pruned method at runtime throws UnsupportedOperationException.

Example usage:


 @Component
 public interface MyComponent {
   @OnlyUsedBy(FooId.class) Foo getFoo();
 }

 class FooAccessor {
   @BindingIdentifier(FooId.class) @Inject FooAccessor() {}

   Foo getFoo(MyComponent component) { return component.getFoo(); }
 }
 
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<?>[]
    The binding identifier classes whose reachability retains this entry point method.
  • Element Details

    • value

      Class<?>[] value
      The binding identifier classes whose reachability retains this entry point method.