Why doesn't the return type satisfy the method signature in the following method?
protected Observable<List<? extends Person>> getLoadPersonsObservable() {
return StudentsProvider.getStudentsProvider().getStudents().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
The observeOn() method returns the following:
Observable<List<Student>>
And here is the Student class:
public class Student extends Person {
public Student(String name, String id, boolean approved) {
super(name, id, approved);
}
}
For now, getStudents() is a stub method, emulating a network call:
@Override
public Observable<List<Student>> getStudents() {
final Observable<List<Student>> fetchStudents = Observable.create(new Observable.OnSubscribe<List<Student>>() {
@Override
public void call(Subscriber<? super List<Student>> subscriber) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
List <Student> stubList = new ArrayList<>();
stubList.add(new Student("Freddie Mercury", "1", true));
stubList.add(new Student("Jimmy Hendrix", "2", true));
subscriber.onNext(stubList);
subscriber.onCompleted();
}
});
return fetchStudents;
}
Thanks in advance! - Mate
First create a custom class for your Observer
then in your activity, add this method
This is just an example of how you can achieve what you are trying.
P.S. This might not be the final solution but it will definitely help you remove the static implementation like in your solution