https://kotlinlang.org logo
#getting-started
Title
# getting-started
s

Stephan Schröder

02/21/2023, 9:58 AM
I recently argued that you can replace Lombok's @Builder annotation in Java with Kotlin constructors with named and optional parameters when converting a Java project into a Kotlin project. But then I was told that this breaks backwards compatibility, so this isn't an option for Java libs with third party users. So what does one do in that case? Write the Builder by hand (doable but tedious) or is there a plugin for Kotlin that does this for you? (I am aware that the Builder support in Kotlins Lombok plugin doesn't help us here, since that only supports to invoke the builder()-function in Java code from Kotlin code, but doesn't generate a builder for Kotlin classes.)
v

Vampire

02/21/2023, 10:15 AM
Imho, make a breaking release, removing the old method 🙂
But other than that, you are not fully correct, Kotlin 1.8 added support for `@Builder`: https://kotlinlang.org/docs/whatsnew18.html#support-for-lombok-s-builder-annotation
s

Stephan Schröder

02/21/2023, 3:07 PM
@Vampire this is exactly what I described at the end. "Kotlin 1.8 supporting @Builder" isn't what you think it is. It doesn't support the @Builder annotation on Kotlin classes(!!!), it's just that Kotlin code now can use Java classes annotated with @Builder within a mixed Java/Kotlin. I'm like 80% sure of this, but might be wrong. But if the support would mean that you could use @Builder on Kotlin classes then the requirement for it to be in a mixed Java/Kotlin module wouldn't make sense. https://kotlinlang.org/docs/lombok.html
v

Vampire

02/21/2023, 3:38 PM
Oh, ok, then I probably misinterpreted that paragraph. I never use Lombok. :-)
s

Stephan Schröder

02/21/2023, 3:45 PM
I even voted for the ticket to add Lombok Builder support for Kotlin assuming it would mean that I can use the annotation on Kotlin classes 😅
54 Views