Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA - Kotlin: Unresolved reference: eq method

Am using IntelliJ IDEA 2019.1.2 (Ultimate Edition) with Kotlin (kotlinc-jvm 1.3.31) on macOS Mojave 10.14.5.

When I created a Kotlin JVM project and added a Kotlin file entitled "Nullability.kt" with the following code (extension function with a main() method):

fun List<Int>.allNonZero() = all { it > 0 }

fun main() {
    val list1 = listOf(1, 2, 3)
    list1.allNonZero() eq true
}

IntelliJ IDEA highlights "eq" in red and it states:

Kotlin: Unresolved reference: eq

How to resolve this from within IntelliJ IDEA?

like image 254
PacificNW_Lover Avatar asked May 21 '19 16:05

PacificNW_Lover


People also ask

How do I fix Kotlin unresolved reference?

Please make sure that you add the id 'kotlin-android-extensions' line on the build. gradle file that's inside your app module. Once you sync the Gradle build, the error should disappear.

How add Kotlin SDK to IntelliJ?

From the main menu, select File | Project Structure | Project Settings | Project. If the necessary SDK is already defined in IntelliJ IDEA, select it from the SDK list. If the SDK is installed on your computer, but not defined in the IDE, select Add SDK | 'SDK name', and specify the path to the SDK home directory.


1 Answers

Found it, inside the Coursera course, Kotlin has a Playground where the code is hidden but you can expand it and view it by clicking on the + sign.

infix fun <T> T.eq(other: T) {
    if (this == other) println("OK")
    else println("Error: $this != $other")
}
like image 162
PacificNW_Lover Avatar answered Oct 21 '22 16:10

PacificNW_Lover