Hi all,
I’m learning Kotlin and I have a doubt. Suppose we have this JAVA classes:
public interface I {
Observable<Integer> getValue();
}
public class C implements I {
private BehaviorSubject<Integer> value;
C(int value){
this.value = BehaviorSubject.createDefault(value);
}
@Override
public Observable<Integer> getValue() {
return null;
}
}
I try to do the same with Kotlin, doing this:
interface I {
val value: Observable<Int>
}
class C(value: Int) : I {
override val value: BehaviorSubject<Int> = BehaviorSubject.createDefault(value)
}
But is not the same.
The problem is when I construct an instance c of C, c.value give me a BehaviorSubject and not and Observable.
I don’t want that the client code sees that value is a BehaviorSubject. This is my internal representation!
How can I obtain the EXACTLY same java code in Kotlin?
Thanks in advance!
Edit: I can’t declare value in c as Observable, because internally I need a BehaviorSubject