P*P 发帖数: 36 | 1 我有一个interface定义了一个method A,两个class implements了这个interface,meth
od A.如果另一个class要调用这个method A,怎么制定要用哪个implementation呢.谢谢 | g*****g 发帖数: 34805 | 2 是那个类的实例就会用那个。
meth
【在 P*P 的大作中提到】 : 我有一个interface定义了一个method A,两个class implements了这个interface,meth : od A.如果另一个class要调用这个method A,怎么制定要用哪个implementation呢.谢谢
| w*r 发帖数: 2421 | 3 instanceof(o).getMethod("methodname").invoke(o,...)
meth
【在 P*P 的大作中提到】 : 我有一个interface定义了一个method A,两个class implements了这个interface,meth : od A.如果另一个class要调用这个method A,怎么制定要用哪个implementation呢.谢谢
| h*********o 发帖数: 62 | 4 That is quite a fancy call.
【在 w*r 的大作中提到】 : instanceof(o).getMethod("methodname").invoke(o,...) : : meth
| w*r 发帖数: 2421 | 5 so far this is the standard way to figure out which method you are hitting.
And it is the basic methodology deployed by spring
【在 h*********o 的大作中提到】 : That is quite a fancy call.
| h*********o 发帖数: 62 | 6 first, I do not see reflective invocation has anything to do with the
original question. maybe I do not see things deep enough.
second, getmethod is a method belongs to class metadata, you can not call it
on an object instance , nor on instanceof operator.
third, getmethod(String) only returns method object. If you can somehow to
figure out which class metadata to use, you already answer the question, no
need to make the function call using reflection. |
|