Kotlin 1.3 & Java 11 & enum


#1

Env is as below
JDK -> OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
Kotlin-> 1.3

I’m having issue with below code. It works perfectly fine on JDK 8. Issue is observed on JDK 11.

enum class TaxReturnFrequencyEnum {
    MONTH {
        override fun calculatePeriod(dueDate: LocalDate) = calculateInternal(dueDate, 1, 0)
    },
    BI_MONTH {
        override fun calculatePeriod(dueDate: LocalDate) = calculateInternal(dueDate, 2, 1)

    },
    QUARTER {
        override fun calculatePeriod(dueDate: LocalDate) = calculateInternal(dueDate, 3, 2)

    },
    ANNUAL {
        override fun calculatePeriod(dueDate: LocalDate) = calculateInternal(dueDate, 3, 2)

    };


    fun calculateInternal(dueDate: LocalDate, step: Int, offset: Int): TaxReturnPeriod {
        //implementation
    }


    abstract fun calculatePeriod(dueDate: LocalDate): TaxReturnPeriod

}

That enum won’t compile on JDK 11. Compilation error is “error: invalid method declaration; return type required
TaxReturnFrequencyEnum() {
^”

it is complaining about constructor generated by kotlin compiler. Did anyone encountered same issue on JDK 11?


#2

Could you please use code highlight wrapper for your code?


#3

@darksnake done!


#4

Your code works for me, java is

C:\projects\tests2>%JAVA_HOME%\bin\java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

project is in kotlin 1.3.10, created from gradle 5.0, using

gradlew init --type kotlin-application --dsl kotlin

and works flawlessly (sans obvious warnings of parameters in calculateInternal never used)


#5

@jakubgwozdz thanks. It turns out issue is down to kapt. My project uses querydsl and Q-classes are generated during the build. It is complaining about constructors on lines 16,29,42.