java method isBridge
来源:互联网 发布:公安部 网络安全监管 编辑:程序博客网 时间:2024/05/19 12:36
isBridge用来判断一个方法是否是桥接方法。
看代码:
package com.reflect;import java.lang.reflect.Method;import junit.framework.TestCase;public class TestBridgeMethod extends TestCase {public void testBridgeA() {class Father {public void test() {}}class Son extends Father {public void test() {}}Method[] methods = Son.class.getDeclaredMethods();for (Method method : methods) {System.out.println(method.toString() + ", " + method.isBridge());}}public void testBridgeB() {class Father<T> {public void test(T t) {}}class Son<T> extends Father<T> {public void test(T t) {}}Method[] methods = Son.class.getDeclaredMethods();for (Method method : methods) {System.out.println(method.toString() + ", " + method.isBridge());}}public void testBridgeC() {class Father<T> {public void test(T t) {}}class Son extends Father<String> {public void test(String s) {}}Method[] methods = Son.class.getDeclaredMethods();for (Method method : methods) {System.out.println(method.toString() + ", " + method.isBridge());}}}
运行testBridgeA,输出:
public void com.reflect.TestBridgeMethod$1Son.test(), false
运行testBridgeB,输出:
public void com.reflect.TestBridgeMethod$2Son.test(java.lang.Object), false
运行testBridgeC,输出:
public void com.reflect.TestBridgeMethod$3Son.test(java.lang.String), falsepublic void com.reflect.TestBridgeMethod$3Son.test(java.lang.Object), true
当父类是泛型,而子类不是泛型时,如果子类重写了父类的方法,那么子类实际上会有两个同名的方法,参数为Object的方法则是桥接方法。
0 0
- java method isBridge
- Java - Method Overloading vs Method Overriding
- java synchronized static method and common method
- java Native Method初涉
- Java Remote Method Invocation
- java Native Method初涉
- java Native Method初涉
- java Native Method
- java Native Method初涉
- Java Reflection 之 Method
- java Method类试用
- java Native Method初涉
- java.lang.reflect.Method
- java Native Method初涉
- java native method
- Java Native Method introduction
- java Native Method初涉
- java thread.join method
- Matlab 高斯消元
- 0400000101
- 0400000102
- 搜索(dfs)
- android Fragment的简单使用
- java method isBridge
- 关于接口的实例
- day21IO流
- Android 原生代码开发的一些小知识
- Linux中创建静态库和动态库
- android Application使用
- Centos5.5安装
- 块设备的处理及通用块层
- 大数乘法(大数乘小数)c语言版