Comments (6)
Got a couple of thoughts here, we could either:
- Be strict like ksp is (I think the metadata is there in the kapt backend to do this)
- Allow types to be 'upgraded' when compatible. This would be similar to how you can do both
foo: Foo = javaMethodThatReturnsFoo()
andfoo: Foo? = javaMethodThatReturnsFoo()
in kotlin.
I'm leaning towards 1 for fewer surprises but it does mean you may have to explicitly declare the return type on a @Provides
in some cases. Maybe an explicit warning/error message here could help?
from kotlin-inject.
I'd prefer option 1 as well.
from kotlin-inject.
I agree with @sunian that as a consumer, option 1 seems to be the safest, most forward looking solution.
Also, may have to explicitly declare the return type on a @Provides in some cases
while slightly inconvenient I wouldn't think that's too bad.
from kotlin-inject.
It's not inconvenient no, but it did take me a bit to figure out what was happening. I had
@Provides fun retrofit(client: OkHttpClient) = Retrofit.Builder().build()
@Provides fun myService(retrofit: Retrofit): MyService = retrofit.create()
and it was complaining that it couldn't find retrofit. Again a targeted warning/error might be good enough though.
from kotlin-inject.
Fixed so the behavior in both back-ends matched. Keeping this open until we can get a better error for this case.
from kotlin-inject.
Ended up disallowing platform types in @Provides
methods. You get a helpful error telling you to declare the return type explicitly. This not only better documents your intent, but means you if you get it wrong (say fun foo(): Foo = javaMethodThatCanReturnNull()
you get a NPE in your code instead of deep in the generated code.
from kotlin-inject.
Related Issues (20)
- Improve documentation to better understand how to use kotlin-inject HOT 4
- Conflicting overloads error when upgrading another library to use KSP 2.0.0 HOT 5
- Can't inject provided dependency into java class HOT 5
- There seem to be no way to define bindings in a separate file (like module for dagger) HOT 2
- Generated code tries to use property or variable that isn't there HOT 1
- Incremental compilation sometimes fails with exception HOT 2
- In some cases scope doesn't apply to provided dependency HOT 1
- Is nesting @Assisted possible? HOT 1
- Support qualifieres in multibinds map keys and set elements. HOT 2
- Resolving type arguments may throw an exception for star projections
- Annotation support for exposing a supertype to the graph HOT 6
- Implementation for scoped components HOT 7
- Critical obfuscation issue. HOT 7
- How to create ViewModel in Jetpack Compose? HOT 2
- How to inject WorkManager? HOT 3
- Checking for cyclic dependencies HOT 1
- KmpComponentCreate not generated for IosSimulatorArm64 HOT 5
- Different behavior between extension property and function when providing a scoped class using `@Qualifier` annotations
- The order of dependencies with `@Qualifier` annotation modifies the scope of the dependency.
- Build fails when declaring two `Lazy` dependencies.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlin-inject.