lundi 23 mars 2020

Can i dynamically generate a class that implements two or more interfaces?

So i am generating class out of single interface by using proxy like so

public interface A {

    default String a() {
        return "a";
    }
}
A a = (A) Proxy.newProxyInstance(
            A.class.getClassLoader(),
            new Class<?>[] { A.class },
            new PassThrough());

and it works fine but im wondering if i can generate the class that has access to every method out of multiple interfaces

public interface A {

    default String a() {
        return "a";
    }

    interface B {

        default String b() {
            return "b";
        }

    }

}

Something like

 AB = ...;
 AB.a();
 AB.b();




Aucun commentaire:

Enregistrer un commentaire