Kotlin & Java+Lombok interop


I’m wondering if it’s possible to have Kotlin recognise Lombok annotated Java code?

For example, given the following class:

public class Person {
   private String firstName

In Kotlin, if I try to invoke person.firstName,I get an error:

Error:(30, 20) Kotlin: Cannot access ‘firstName’: it is ‘private’ in ‘Person’

I assume that this is because at the time when the Kotlin/Java interop runs, Lombok hasn’t yet instrumented the code.

Are there any workarounds to this?


If you put Java and Kotlin code in different modules, it should work. Rationale: Kotlin will see whatever declarations get to the byte code, but it can’t see whatever Lombok generates on-the-fly in the source code


Well we use Java and Kotlin in the same module and I cannot imagine splitting it between modules as we are slowly rewriting everything to Koltin. I tried to add the kapt preprocessor, but it still complains that cannot access “field”: it is private in “Entity”.