Hello, I got one question about Kotlin-Java, when ...
# announcements
o
Hello, I got one question about Kotlin-Java, when we use Kotlin we don’t write builders since we have named arguments + default values, that’s ok, but what in case we write library in Kotlin and this library will also be used in Java project? It would be messy, we end up with constructor with
n
arguments. Is there a way to generate proper builder for Java? Some sort of annotation like
@JvmOverloads
m
outlying: no there is not
you can use the annotation you mentioned to generate additional methods for each argument specified
👍 1
Copy code
@JvmOverloads
    fun someMethod(a: Int = 0, b: Int = 0, c: Float = 0f, d: String = “”){
        
    }
generates this:
Copy code
@JvmOverloads
   public final void someMethod(int a, int b, float c) {
      someMethod$default(this, a, b, c, (String)null, 8, (Object)null);
   }

   @JvmOverloads
   public final void someMethod(int a, int b) {
      someMethod$default(this, a, b, 0.0F, (String)null, 12, (Object)null);
   }

   @JvmOverloads
   public final void someMethod(int a) {
      someMethod$default(this, a, 0, 0.0F, (String)null, 14, (Object)null);
   }

   @JvmOverloads
   public final void someMethod() {
      someMethod$default(this, 0, 0, 0.0F, (String)null, 15, (Object)null);
   }
o
Thanks for explaining 🙂 I’m familliar with
@JvmOverloads
I think it’s an issue, since we have
@JvmOverloads
we should have something similiar, OFC I can write eg. Gradle plugin for that but I want to start with question, maybe there is such a tool
k
if java consumers is a big concern for you, maybe you should write builders or let them be generated, e.g. by autovalue