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.

@JvmStatic in @Module companion object is not supported

See original GitHub issue

With the release of 2.25.2, @JvmStatic is not needed anymore for the @Module object classes, however we still have to use them for the @Module companion objects

Current solution example for avoiding it from companion objects:

@Module(includes = [FooModule.Static::class])
abstract class FooModule {
   @Binds
   abstract fun providesFoo() : Foo

   @Module
    object Static{
       @Provides
       fun providesFooStatic() : FooStatic
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
danysantiagocommented, Feb 19, 2020

Companion objects are now supported in 2.26.

1reaction
hrskrscommented, Oct 24, 2019

IIUC you’re expected to move to using an object.

That is a solution, but would be good to support objects too. We dont always want to have multiple coupled modules with different naming

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dagger 2 static provider methods in kotlin - Stack Overflow
Now Dagger2 (version 2.26) support companion objects in @Module annotated classes in kotlin withthouh @Module and @JvmStatic annotations.
Read more >
Method in companion object is not found when calling from ...
If you want something to be available as a static method from Java/Groovy/etc, you need to annotate it as @JvmStatic . Does this...
Read more >
Best Practices Kotlin Dagger Module with @Binds ... - Reddit
I am working on a new project where I'm using Hilt and Kotlin. ... 2 of these ways include not using a companion...
Read more >
[Solved]-Dagger 2 static provider methods in kotlin-kotlin
This is not directly possible but with two nested modules (as Omar Al Halabi ... Now Dagger2 (version 2.26) support companion objects in...
Read more >
Java Calling Kotlin - CommonsWare
@JvmStatic. Whether you use @file:JvmName() or not, Java can call top-level Kotlin functions. When it comes to functions on a companion object, things...
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