class A class B private fun Any.test(): Int = when { this is A && a -> 10 this is B && b -> 2 else -> 0 }