4

I use Otto event bus to subscribe for Volley Requests. I want to use this generic class but the wrong fragment (subscriber) tries to handle the event. Is it possible to use a generic class or is randomly every subscriber of the VolleyResultEvent, independent of the generic type, called?

public class VolleyResultEvent<T> {

    public final VolleyResult result;
    public final T content;

    public VolleyResultEvent(VolleyResult result, T content) {
        this.result = result;
        this.content = content;
    }

    public enum VolleyResult {
        SUCCESS, ERROR
    }

}
Sven Mäurer
  • 715
  • 1
  • 9
  • 19

1 Answers1

4

Every subscriber of VolleyResultEvent will be called regardless of type generics. Either would you want to make several subclasses of VolleyResultEvent according to the number of types you're having; or implement a matching function which, for example, would compare event id (or type) with subscriber's id (or type) and allow further processing if those are equal.

Alex Dmitriev
  • 3,664
  • 3
  • 29
  • 35