java 8 - how to call default method in interface use reflection -


public interface testserviceiface {     default string test(string str, int flag) {         return str;     } } 

interface this,if implements interface, , have instance ,how can call default method? if use reflection, how do? , have interface,no impl class , no impl instance.how call default method?

you can access interface default methods reflection below:

class<testserviceiface> type = testserviceiface.class;  method defaultmethod = type.getmethod("test", string.class, int.class);  string result = (string) defaultmethod.invoke(instance, "foo", 0); 

however, if subclass override default method, overrided method called, means interface default method supports polymorphism.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -