Tim Schraepen
09/30/2022, 1:43 PMIn Book.kt:
data class Book(val isbn: ISBN, val title: Title)
@JvmInline value class ISBN(val value: String)
@JvmInline value class Title(val value: String)
Somewhere in BookDAO.java:
new Book("123","Thundercats");
When I'm looking at the code in IntelliJ, it's simply compiling (no red squiggly lines).
When I run a mvn clean install
it also just compiles.
But when I do a build (ctrl+F9), I'm getting this:
java: Book(java.lang.String,java.lang.String) has private access in Book
When I define book as
data class Book(val isbn: String, val title: String)
compilation does succeed.
What is going on? It smells like intelliJ is using an older Kotlin version to compile or something?
In the build output I'm getting this:
...
Kotlin: kotlinc-jvm 1.7.20 (JRE 17.0.2+8)
...
javac 11.0.9 was used to compile java sources
I'd like to try to get kotlinc-jvm to use JRE 11 to compile, but don't know how.Tim Schraepen
09/30/2022, 1:48 PMephemient
09/30/2022, 1:48 PMTim Schraepen
09/30/2022, 2:06 PMin Book.kt
data class Book(private val _isbn: String, private val _title: String){
val isbn: ISBN
@JvmName("getIsbn") get() = ISBN(_isbn)
val title: Title = Title(_title)
}
@JvmInline value class ISBN(val value: String)
@JvmInline value class Title(val value: String)
Somewhere in BookDAO.java:
book.getIsbn()
book.getTitle()
Same issue, IntelliJ the editor is not showing any issues, and even provides auto-completion hints for both .getIsbn() and .getTitle().
Build Output:
java: cannot find symbol
symbol: method getTitle()
location: variable book of type Book
Tim Schraepen
09/30/2022, 2:22 PM<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
in my pom.xml.
Setting it to false actually produces a publically visible constructor with the value classes inlined, like you'd expect, and also generates the correct getters, during compilation (build output).