Czy tokeny generyczne i (super?) Typu mogą pomóc w zbudowaniu bezpiecznego agregatora wiadomości?

Mam to podstawoweNews berło

interface News {
    String getHeader();
    String getText();
}

i takie konkretne klasySportsNews iFinancialNews zapewnić konkretne metody, takie jakgetStockPrice(), getSport() i tak dalej. Wiadomości będą wysyłane do a

interface Subscriber<N extends News> {
    void onNews(N news);
}

Problem polega na tym, jak zarejestrować i utrzymać subskrypcje. Pierwsze podejście, które próbowałem, polegało na użyciu centralnegoAggregator, zachowując mapę międzyClass<T> obiekty iSet<Subscriber<T>>, ale wkrótce to podejście okazało się nieopłacalne. Oto pożądane API

public class Aggregator {

    public <N extends News> void subscribe(Subscriber<N> subscriber) {
        // TODO somehow (super type token) extract N and 
        // add the item to the set retrieved by getSubscribersFor()
    }

    public <N extends News> void dispatch(N news) {
        for (Subscriber<N> subscriber: getSubscribersFor(news.getClass())) {
            subscriber.onNews(news);
        }
    }

    private <N extends News> Set<Subscriber<N>> getSubscribersFor(Class<N> k) {
        // TODO retrieve the Set for the specified key from the Map
    }
}

Czy jest jakaś alternatywa, aby być bezpiecznym? Czy Java może rozwiązać ten problem w ogóle? włożyłemto małe demo online aby pomóc ci lepiej zrozumieć, czym naprawdę jest problem.

AKTUALIZACJA

Alternatywą byłoby zrobićAggregator sam sparametryzowany z aktualnym typem wiadomości. Byłoby dobrze, z wyjątkiem tego, że jest to problem z kurczakiem i jajkiem: teraz trzeba znaleźć sposób na odzyskanie agregatora. W Javie nie ma sposobu na wyrażenie następujących informacji

interface News {
    static Aggregator<CurrentClass> getAggregator();
}
static metoda nie może byćabstractnie ma możliwości odniesienia się doaktualny typ w argumencie typu

questionAnswers(4)

yourAnswerToTheQuestion