Home > OS >  Generic Method in Java with out parameters
Generic Method in Java with out parameters

Time:03-13

I am trying to implement something similar to EventBus implemented in eshopOnContainers.

Is it Possible to define a method like this in java & read the meta data about T and TH at runtime ? There can be multiple classes extending IntegrationEvent(e.g. PriceChangedEvent) & we should be able to Identify the exact class name at runtime.

public <T extends IntegrationEvent, TH extends IntegrationEventHandler<T>> void subscribe() {
       
        
}

CodePudding user response:

You can pass type info into method:

        public <T extends IntegrationEvent, TH extends IntegrationEventHandler<T>> void subscribe(java.lang.Class<T> tClass, java.lang.Class<TH> thClass) {

        }

Probably Guava Event Bus will be useful for you.

  • Related