Tomáš Záluský napsal(a):
To je dobré! :-)getGenericSuperclass().getActualTypeArguments()
Ještě jsem si přes víkend uvědomil, že to půjde i s použitím interface, protože existuje i getGenericInterfaces().getActualTypeArguments() takže tady je nová verze s interface: package cz.makub.generika; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; /** * Created by IntelliJ IDEA. * * @author Martin Kuba [EMAIL PROTECTED] */ public class Beranek { public static interface Plugin<V> { boolean execute(V param); } public static abstract class A<T> { public void uzijPlugin(String name) { try { System.out.println("----"); System.out.println("plugin: " + name); Class<T> tClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; System.out.println("A<" + tClass.getName() + ">"); Class c = Class.forName(name); Type[] genericInterfaces = c.getGenericInterfaces(); for (Type genericInterface : genericInterfaces) { if (genericInterface instanceof ParameterizedType) { Type type = ((ParameterizedType) genericInterface).getRawType(); if (type.equals(Plugin.class)) { Class vClass = (Class) ((ParameterizedType) genericInterface).getActualTypeArguments()[0]; System.out.println("Plugin<" + vClass.getName() + ">"); if (tClass.equals(vClass)) { System.out.println("jde to"); } else { System.out.println("nejde to"); } } } } } catch (ClassNotFoundException e) { e.printStackTrace(); } } } public static class PotomekAStringovy extends A<String> { } public static class PluginStringovy implements Plugin<String> { public boolean execute(String param) { return false; } } public static class PluginIntegerovy implements Plugin<Integer> { public boolean execute(Integer param) { return false; } } public static void main(String[] args) { PotomekAStringovy pas = new PotomekAStringovy(); pas.uzijPlugin("cz.makub.generika.Beranek$PluginStringovy"); pas.uzijPlugin("cz.makub.generika.Beranek$PluginIntegerovy"); } } Makub -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Supercomputing Center Brno Martin Kuba Institute of Computer Science email: [EMAIL PROTECTED] Masaryk University http://www.ics.muni.cz/~makub/ Botanicka 68a, 60200 Brno, CZ mobil: +420-603-533775 --------------------------------------------------------------
smime.p7s
Description: S/MIME Cryptographic Signature