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.

Respect other Optional<T> types

See original GitHub issue

It’d be great if Optional<T> types other than Guava and Java 8 would be accepted by Dagger 2. It’s costly to include all of Guava in an Android app, and using Java 8 APIs aren’t an option for many apps, due to only being available on API 24+.

Happy for another alternative though - we just need working optional/nullable binding functionality.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
gildorcommented, Sep 6, 2018

Dagger could do that, but I don’t think we want a world with Guava’s Optional, Java8’s version, and custom versions

But there are cases when it makes sense: Guava is a big library and it’s doesn’t sound reasonable to include it just because of Optional even if you use ProGuard Java 8 Optional is not available on Android before API level 24 (pre-24 devices is about 70%)

I still like an idea about Optional factory, but maybe an alternative solution Dagger could provide own very simple Optional implementation for such cases as separate artifact or as part of runtime library (something like DaggerOptional or OptionalDependency)

4reactions
JakeWhartoncommented, Jun 2, 2017

One way would be:

public class AnyClass {
  @dagger.OptionalFactory
  public static <T> com.example.Optional<T> anyName(@Nullable T value) {
    return com.example.Optional.fromNully(value);
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Respect from a Boss You Respect - Springer
Interpersonal respect can be differentiated into two kinds: (1) horizontal respect, i.e. treating someone with dignity; and (2) vertical ...
Read more >
RAINN Uber
RAINN and Uber have teamed up to provide tips for the best ways to respect others while driving and riding with Uber. Working...
Read more >
Teaching Kids Respect in the Classroom
Recognize students when they demonstrate kindness, good manners, empathy, and respect for others. This intentional acknowledgment leads to positive outcomes.
Read more >
List of rules - Respect\Validation - Read the Docs
List of rules. Types. ArrayVal · ArrayType · BoolVal · BoolType · CallableType · Countable · Date · FalseVal · FloatVal · FloatType...
Read more >
c++ - Do std::optional and boost::optional respect alignment ...
The contained value shall be allocated in a region of the optional storage suitably aligned for the type T. An implementor could use...
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