question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BindsInstance is optional

See original GitHub issue

If a method annotated with BindsInstance is not invoked, then the injected field is nullable. Why can’t it be made required to invoke the method? If the method is not invoked, then it can be removed to any clutter in the first place.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
ronshapirocommented, Oct 25, 2018

I didn’t fully understand. Are you saying that today, it’s not required to invoke @BindsInstance methods? I think that’s only the case if a @Nullable annotation is used together with @BindsInstance.

Or are you proposing a feature?

0reactions
bangarharshitcommented, Oct 25, 2018

Got it. Wish somehow these injections (@Inject) can be marked as nullable or optional.

Also, from the doc:

 * <p>{@code @BindsInstance} methods must be called before building the component, unless their
 * parameter is marked {@code @Nullable}, in which case the component will act as though it was
 * called with a null argument. Primitives, of course, may not be marked {@code @Nullable}.

It seems the methods in which parameters are not marked as Nullable should always be called. Maybe fix the javadoc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BindsInstance - Dagger
Marks a method on a component builder or a parameter on a component factory as binding an instance to some key within the...
Read more >
how it works @BindsInstance dagger 2 - Stack Overflow
@bindsInstance is used for removing constructor from module and chaining modules where you get component. Without @BindsInstance
Read more >
Avoid Nullable dependencies in Dagger2 with ... - Medium
Many functional programming libraries don't even allow us to pass null values in the system, and Optional comes really handy dealing with these ......
Read more >
dagger.BindsInstance.<init> java code examples - Tabnine
BindsInstance abstract Builder application(Application application); ... @TestingPlugins Optional<ImmutableSet<BindingGraphPlugin>> testingPlugins);.
Read more >
Stop Holding Dagger by the Blade: Use the Hilt | Infinum
Builder interface Builder { @BindsInstance fun application(application: ... Step 4 (Optional): Integrate Hilt with ViewModels.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found