Say I have this Java and Kotlin interfaces:
public interface JavaInterface {
void onTest();
}
interface KotlinInterface {
fun onTest()
}
Why can't I create an instance of Kotlin interface without constructor?
// this is okay
val javaInterface: JavaInterface = JavaInterface {
}
// compile-time exception: interface does not have constructor
val kotlinInterface1: KotlinInterface = KotlinInterface {
}
// this is okay
val kotlinInterface2: KotlinInterface = object : KotlinInterface {
override fun onTest() {
}
}
Why can't I create an instance of KotlinInterface
the way I did with JavaExample
just like the first example?