1、弄明白 static 与普通方法的区别。
通俗点来说方法名只是个地址引用,static 方法的引用是个绝对地址,因此可以直接能找到。(个人理解为,对于static的变量与方法,编译期就确定了位置)
对于非 static 方法来说,是个相对地址,或者说是个地址的偏移量,只有等对象的引用产生
后通过偏移量才能计算出实际的地址,因此非 static 方法[color=red]只能通过对象[/color]来进行调用。
2、示例
public static void main(String[] arg0) {
[color=red]ReflectTest a= new ReflectTest();[/color]
[color=red]a.[/color]reflect(new Base(),"priString","priMethod");
}
通俗点来说方法名只是个地址引用,static 方法的引用是个绝对地址,因此可以直接能找到。(个人理解为,对于static的变量与方法,编译期就确定了位置)
对于非 static 方法来说,是个相对地址,或者说是个地址的偏移量,只有等对象的引用产生
后通过偏移量才能计算出实际的地址,因此非 static 方法[color=red]只能通过对象[/color]来进行调用。
2、示例
public static void main(String[] arg0) {
[color=red]ReflectTest a= new ReflectTest();[/color]
[color=red]a.[/color]reflect(new Base(),"priString","priMethod");
}