Olekss
01/10/2020, 10:31 AMspand
01/10/2020, 10:36 AMspand
01/10/2020, 10:36 AMOlekss
01/10/2020, 10:42 AMMarat Akhin
01/10/2020, 10:42 AMinterface A
interface B
fun foo(a: Any) {
a as A
a as B
bar(a)
}
fun <T> bar(t: T) where T : A, T : B {}
UPD: However, in most cases you can achieve the same thing in a safer fashion with if (a is A) ... if (a is B)
chain, as smart casts support such a case as wellOlekss
01/10/2020, 10:45 AMinterface Interface1 {
val v1:String
}
interface Interface2 {
val v2:Int
}
class ExperimentalClass : Interface1, Interface2 {
override val v1 : String = "ABC"
override val v2 : Int = 42
}
fun <T> printStuff(value:T) where T : Interface1, T:Interface2 {
println(value.v1)
println(value.v2)
}
fun doSomething(obj:Any) {
// if (obj is Interface2 && obj is Interface1) printStuff(obj)
obj as Interface2
obj as Interface1
printStuff(obj)
}
fun main() {
val e = ExperimentalClass()
doSomething(e)
}
Olekss
01/10/2020, 10:45 AMMarat Akhin
01/10/2020, 10:47 AM-Xnew-inference
Olekss
01/10/2020, 10:49 AMMarat Akhin
01/10/2020, 10:52 AM-Xnew-inference
and 1.3.40; consequently, IDEA does not show any errors exactly because it switched to the new inference engine under the hood some time ago 😃Olekss
01/10/2020, 10:55 AM