Posts

Showing posts with the label behaviorsubject

How to convert BehaviorSubject<Optional - > to Kotlin?

How to convert BehaviorSubject<Optional<List<File>>> to Kotlin? I have BehaviorSubject in RxJava, but I am not able convert it to Kotlin. public class Test { private final BehaviorSubject<Optional<List<File>>> fileList = BehaviorSubject.createDefault(Optional.absent()); void test() { File file = new File(""); fileList.getValue().get().add(file); } } This is converted BehaviorSubject to Kotlin, but I am not able to ADD object (file) to list. class Test { private val fileList = BehaviorSubject.createDefault(Optional.absent<List<File>>()) internal fun test() { val file = File("") fileList.value.get().add(file) } } I have following imports: implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' implementation 'io.reactivex.rxjava2:rxjava:2.1.13' implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0' 1 Answer ...