"One" gets the paradigm type of the implementation class of the generic interface
(1) Fan-type interface
Package Org.springframework.context; Import Java.util.EventListener; Public Interface extends extends EventListener { /** * Handle an application event. @param event the event to respond */ void onapplicationevent (E event);}
View Code
(2) Fan type interface implementation class
Package Com.mobile.thinks.login.listen; Import Org.springframework.context.ApplicationListener; Import com.mobile.thinks.login.event.BaseEvent; Public class Implements Applicationlistener<baseevent>{ @Override publicvoid Onapplicationevent (BaseEvent event) { } }
View Code
(3) generic type of class for interface implementation classes
Package com.mobile.thinks.login.event; Import org.springframework.context.ApplicationEvent; Public Abstract class extends applicationevent { public baseevent (Object source) { super (source); } }
View Code
(4) Gets the type of the pattern's fill class
Public Static voidMain (string[] args) {Loginlisten Listen=NewLoginlisten (); Class<?> CLS =Listen.getclass (); //Cls==>class Com.mobile.thinks.login.listen.LoginListenSystem.out.println ("cls==>" +CLS); Type[] Type=cls.getgenericinterfaces (); Type Types=Cls.getgenericsuperclass (); for(inti=0;i<type.length;i++) {Type ty=Type[i]; if(TyinstanceofParameterizedtype) {type[] stypes=((parameterizedtype) Ty). Getactualtypearguments (); for(intj=0;j<stypes.length;j++) {Type CLSA=Stypes[j]; //model type ==>class com.mobile.thinks.login.event.BaseEventSystem.out.println ("Paradigm type ==>" +(Class) CLSA); } } } }View Code
Related operations walkthrough for "Java Reflection" class type