How to convert BehaviorSubject<Optional - > to Kotlin?

Multi tool use
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
1
Kotlin distinguishes between immutable Lists (the default), and MutableLists. Declare a MutableList instead.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.