Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to define Functional (SAM) interfaces

In Kotlin, i'm trying to define an Interface with only one method. When trying to the following code:

  fun interface someInterFace
{
    fun someFunc()
}

I'm getting the following error message: "expecting function name or receiver type" Can someone explain me what i'm doing wrong? I'm using it exactly as it described in: Functional (SAM) interfaces

like image 399
Eitanos30 Avatar asked Jun 06 '26 09:06

Eitanos30


1 Answers

You need to change the languageVersion of kotlin to 1.4 or above that. For that, you do not have to change the version of ext.kotlin_version to 1.4+, but You need to write just a few lines in build.gradle file:

kotlinOptions {
    jvmTarget = '1.8'
    languageVersion = "1.4"
}

You can now sync the gradle and your code will work now.

like image 180
krupa parekh Avatar answered Jun 07 '26 22:06

krupa parekh