Dynamic method dispatch

前端 未结 2 1079
春和景丽
春和景丽 2021-01-24 17:10

There is lot of info on Dynamic dispatch in the internet, I feel like a chicken as I am not able to implement it. Please help me. Here is what I am trying to do.



        
2条回答
  •  无人共我
    2021-01-24 17:33

    Try loading ClassC with reflection. If that attempt fails, your ClassC does not exist so the validation is OK by default. If ClassC exists, try finding the proper method and calling it with reflection too. If you don't find the method, then the validation is again OK by default (I guess). If you find the method, and the call to it returns true, then you're done, validation is OK. And if this call returns false, the validation failed.

    Check these links, and I think you should get what I am saying.

    http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#forName%28java.lang.String%29

    http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getMethod%28java.lang.String,%20java.lang.Class...%29

    http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Method.html#invoke%28java.lang.Object,%20java.lang.Object...%29

提交回复
热议问题