Quick Answer

Referencing function without calling it

Understanding the Issue

This error occurs when you reference a function but forget to call it (with parentheses), or when the compiler expects a function call but finds something else.

The Problem

This code demonstrates the issue:

Kotlin Error
// Problem: Missing invocation
fun greet() = println("Hello")
val greeting = greet // Error

The Solution

Here's the corrected code:

Kotlin Fixed
// Solution 1: Call the function
val greeting = greet() // Correct

// Solution 2: Get function reference
val greetingFunc = ::greet // Function reference

// Solution 3: Proper lambda syntax
val greeting = { greet() }

Key Takeaways

Ensure functions are properly invoked with () or referenced with :: when needed.