How to 'wrap' two classes with identical methods?

前端 未结 6 958
误落风尘
误落风尘 2021-02-15 10:52

I have to handle two classes with identical methods but they don\'t implement the same interface, nor do they extend the same superclass. I\'m not able / not allowed to change t

6条回答
  •  粉色の甜心
    2021-02-15 11:54

    You probably can exploit a facade along with the reflection - In my opinion it streamlines the way you access the legacy and is scalable too !

    class facade{
    
     public static getSomething(Object AorB){
        Class c = AorB.getClass();
        Method m = c.getMethod("getValueOne");
        m.invoke(AorB);
     }
     ...
    
    }
    

提交回复
热议问题