díky, to je přesně to co jsem hledal
Dne Monday 16 of June 2008 11:30:24 Martin Kuba napsal(a):
> 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
--
Martin Beránek