Kotlin
Parameter hints
Show property type hints | Controls whether hints should appear when assigning a value to a property whose type is not explicitly specified.
class User(_id: Int = 0) {
val id = _id // inferred property type
}
|
Show function return type hints | Controls whether hints should appear for functions with inferred return types.
fun sum(i1: Int, i2: Int) = i1 + i2
// the return type (Int) is inferred
|
Show local variable type hints | Controls whether hints should show the type when a local variable, whose type is not specified, is assigned some value. The type is not shown for constants.
fun returnHello(): String = "Hello"
fun hintsDemo() {
val s = returnHello()
// "s" gets the String type
}
|
Show parameter type hints | Controls whether hints should appear for lambda parameters without a type.
fun hintsDemo() {
listOf(1, 2, 3).filter { elem -> // parameter with inferred type
elem >= 3
}
}
|
Show argument name hints | Controls whether hints should appear for function and constructor arguments.
data class User(val id: Int)
fun printSum(a: Int, b: Int) { println(a + b) }
fun hintsDemo() {
val u = User(0) // calling constructor
printSum(1, 1) // calling function
}
|
Show lambda return expression hints | Controls whether hints should appear for multiline lambdas that return a value. This is useful in complex constructs, where it is easy to forget that a lambda is returning something.
fun numbers(): String {
val numbers = StringBuilder()
return with(numbers) {
// "with" structure starts here
for (letter in '0'..'9') {
append(letter)
}
toString() // used as the return value
}
}
|
Show hints for implicit receivers and parameters of lambdas | Controls whether hints should appear for lambdas' implicit receivers.
fun numbers(): String {
val numbers = StringBuilder()
return with(numbers) {
// the implicit receiver is "numbers" (StringBuilder)
for (letter in '0'..'9') {
append(letter)
}
toString()
}
}
|
Show hints for suspending calls | Controls whether hints should appear for suspending calls.
fun hintsDemo() {
doSomethingUsefulOne() // calling a suspending function
}
suspend fun doSmth(){
delay(1000L)
println("Inside a suspending function")
}
|
Black list | Allows you to specify classes for which inlay hints will not be displayed. |
Last modified: 08 May 2020