Java interoperability with Kotlin constructors


#1

Hi community,

Having recently started using Kotlin I’ve been enjoying named and optional constructor arguments. I’m finding that we get the benefits of a Builder Pattern with a significant reduction in code.

Unfortunately the Java end users of our API have to deal with a constructor that takes too many arguments. @JvmOverloads doesn’t really address the problem nicely. The standard Java approach to this problem would be to provide a Builder for the object.

Does there exist or has there been any thought to providing a constructor annotation that would generate a Builder to provide Java users with the same benefits as our native Kotlin constructor? eg. optional, named parameters in and an immutable object in return?

Thanks,
Mike


#2

But unfortunately, no answer yet