Home > Software engineering >  Questiion about the principle of Unit Kotlin
Questiion about the principle of Unit Kotlin

Time:11-25

I am new to Kotlin and I have question as I dont fully understand the principle of Unit:

onChecked:(Boolean) -> Unit

Does it pass the certain data as parameter to other function ( as a Unit)?

CodePudding user response:

(Boolean) -> Unit is a function type. Before the arrow are the parameters, in this case a Boolean and after the arrow is the return type. Unit simply means that it doesn't return anything.

See also this documentation

CodePudding user response:

Unit is method signature which actually return nothing like to java void.

for example: Kotlin

fun onChecked(isCheck: Boolean): Unit {
  //TODO
}

Java

public void onChecked(boolean isCheck) {
//TODO
}

Both are similar

  • Related