File: UseBinds.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (21 lines) | stat: -rw-r--r-- 788 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
A @Provides or @Produces method that returns its single parameter has long been
Dagger's only mechanism for delegating a binding. Since the delegation is
implemented via a user-defined method there is a disproportionate amount of
overhead for such a conceptually simple operation. @Binds was introduced to
provide a declarative way of delegating from one binding to another in a way
that allows for minimal overhead in the implementation. @Binds should always be
preferred over @Provides or @Produces for delegation.

For instance, the following `@Provides` method

```java
@Provides static Heater provideHeater(ElectricHeater heater) {
  return heater;
}
```

is equivalent to the following preferred `@Binds` method.

```java
@Binds abstract Heater bindHeater(ElectricHeater impl);
```