mercredi 30 décembre 2015

Java Interface Derived From Class?

I'm working on an Android framework (http://ift.tt/1QZATJW) which takes data model classes and uses reflection to update views when they are created or updated. I use a dynamic proxy factory for this, and I currently have the user enter both the real object and an interface that specifies any state changing methods. My question is, is there a way the code could auto generate an interface from the class? It would look something like this.

Class<?> derivedInterface = somehowGetAnInterface(Original.class)

Where original is an instance something like:

public class Original {
    String someData;

    public void setSomeData(String s) {
        someData = s;
    }

    public String getSomeData() {
        return someData();
    }
}

And derived interface gets created either at compile time or run time but looks something like this:

public interface OriginalInterface {
    public void setSomeData(String s);
    public String getSomeData();
}





Aucun commentaire:

Enregistrer un commentaire