How to convert BehaviorSubject<Optional - > to Kotlin?

Multi tool use
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.

bjI3ppC2E1BKvdLXibBZ,7X0kLLd,J y I8,6Q Y S,n8KvUiSU6 K3,e0I k5m9OrKLNGmmOoE5BkK
SlnBQrw09JxSZy 1W2rTE0yO,Zfpakj3 PL80j5i4F7pSqct5 VGPq3

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters