Actually I had to add `fun MutableEntity.postSomet...
# announcements
d
Actually I had to add
fun MutableEntity.postSomething() = postSomething
b
you should also be able to do
(mutableEntity as LockedEntity).postSomething()
d
Sorry I guess I didn’t got your point 🙈
b
Wait, so it’s working for you, or my comment was vague and confusing? 🙂
d
I deleted my first comment because I misinterpreted the scenario, I though it could working, but in a class that inherit from
Scope
, in that case it will obviously work, also without any casting. Outside of a
Scope
class I can't see how it could work 🤔
s
It can help to check the compiled code for this. For the example where when() is used compiles to this.
Copy code
public static final void main() {
      MutableEntity var0 = new MutableEntity();
      int var2 = false;
      var0.postSomething1((LockedEntity)var0);
   }
My understanding is that when
when
is compiled it casts the variable which is unpacked. In this case, the compiler is able to cast the variable to the correct parent interface to allow the function.
If you change the Scope interface with something like this. it would also work.
Copy code
interface Scope {
   fun postSomething()
}
It is throwing an error from the compiler. But I’m not familiar enough with the way the kotlin compiler works.
d
>>If you change the Scope interface with something like this. it would also work.
Copy code
interface Scope {
   fun postSomething()
}
Yes, it will work but I don't have any reference to the entity for work with 😅 In my scenario my entity wraps an Android
LiveData
and I want reproduce something like that:
Screenshot_20190329-074900.png
So, basically, the scope is just an empty interface used for say "hey, I can publish to this entity"