How to 'wrap' two classes with identical methods?

前端 未结 6 721
萌比男神i
萌比男神i 2021-02-15 10:50

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:29

    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);
     }
     ...
    
    }
    

提交回复
热议问题