fun main(args: Array?) { val y: Unit = Unit //do not compile A() //do not compile C(Unit) //do not compile //do not compile System.out?.println(fff(Unit)) //do not compile System.out?.println(id(y)) //do not compile System.out?.println(fff(id(y)) == id(foreach(Array(0,{0}),{(e : Int) : Unit -> }))) //do not compile } class A() class C(val value: T) { fun foo(): T = value } fun fff(x: T) : T { return x } fun id(value: T): T = value fun foreach(array: Array, action: (Int)-> Unit) { for (el in array) { action(el) //exception through compilation (see below) } } fun almostFilter(array: Array, action: (Int)-> Int) { for (el in array) { action(el) } } fun box() : String { val a = Array (3,{-1}) a[0] = 0 a[1] = 1 a[2] = 2 foreach(a, { (el : Int) : Unit -> System.out?.println(el) }) almostFilter(a, { (el : Int) : Int -> el }) main(null) return "OK" }