Вопрос

I'm trying to make a collection of observables and then add an observable into that collection.

Right now in this code, it's saying = new Observable<ArrayList<DMRegistration>>(); has protected access in rx.Observable and will not instantiate.

Also with dmRegistrations.add(dmRegistration); it complaining about add saying that it cannot resolve method 'add(rx.Observable)'

I'm very new with observables and have Googled around but have found nothing that provided information leading to a possible solution. Am I approaching this the wrong way?

@Override
public Observable<Collection<DMRegistration>>getAllRegistrations() throws DMException{
    try{
        Observable<Collection<DMRegistration>> dmRegistrations = new Observable<ArrayList<DMRegistration>>();
        Observable<DMRegistration> dmRegistration = execute(get(baseUrl + "registrations"), DMRegistration.class);
        dmRegistrations.add(dmRegistration);
        return dmRegistrations;

    }catch(RestException e){
        throw new DMException(e);
    }
}
Это было полезно?

Решение

Well, if the Observable constructor has protected access, then you can't use it unless you're working in the Observable class or a subclass of Observable. So if you want to make this work with minimal changes you'll have to either make this class a subclass of Observable or make the constructor public, but depending on your situation that may or may not be possible.

The reason the compiler is complaining about being unable to resolve add(rx.Observable) is because it means exactly what it says. It can't find a method matching that combination of name/parameter in the Observable class. Could be because the way you have Observable parameterized, as it appears that add() is looking for a different type than you want to put in.

I'm making a bit of a guess here as to the structure of Observable, but the type of element that you're trying to add doesn't seem to match the type of element that dmRegistrations takes. You declared that dmRegistrations is Observable<Collection<DMRegistration>>, which (I assume) means that you're observing Collection<DMRegistration>. You're trying to add an object of type Observable<DMRegistration>, which isn't what add() is looking for, unless Observable implements Collection.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top