解决方案 »
- java.sql.SQLException: No suitable driver
- Jtree 数据库 出现java.lang.NullPointerException
- 一个很简单的问题,怎么就不会呢?为啥components[i].getName()取出来的值总是null?
- java中树、节点生成问题
- zai win2000 profession zhong bu neng qie huan shu ru fa ?
- JAVA中的线程问题 求大神 轻喷 新手一枚
- 高手帮忙,一个想爆头的问题,从文件里面读出一个 double 型的数据。
- 正在下载JB7个人版?不知道它能做些什么?
- 关于java getBytes()的疑问-编码转换相关
- dom4j解析xml 修改节点值时报错,求破!
- 求助:Excel文件的读取 与 相同位置的单元格数据 汇总
- jdbc数据库连接每天瞬间断开问题:使用的是proxool连接池,异常类似You can't perform....,请高手指点,在线等....
Subclass me = new Subclass();相当于Super me = new Subclass();new子类当然要初始化他的父类了,又其父才有其子么!
* Returns the runtime class of this {@code Object}. The returned
* {@code Class} object is the object that is locked by {@code
* static synchronized} methods of the represented class.
*
* <p><b>The actual result type is {@code Class<? extends |X|>}
* where {@code |X|} is the erasure of the static type of the
* expression on which {@code getClass} is called.</b> For
* example, no cast is required in this code fragment:</p>
*
* <p>
* {@code Number n = 0; }<br>
* {@code Class<? extends Number> c = n.getClass(); }
* </p>
*
* @return The {@code Class} object that represents the runtime
* class of this object.
* @see Class Literals, section 15.8.2 of
* <cite>The Java™ Language Specification</cite>.
*/
public final native Class<?> getClass();明白了?
这个我也知道,我就是不清楚那个引用类型是什么时候从子类变成父类的?
那就应该研究extends的内部机制了,不过这个在源码中不知道还有没有。
结果就是继承自|X|的某个类,而|X|就是getClass方法在哪个类中被调用的,结果其实就是返回该对象的最远代子类,其实也就是重载了。就相当于你调用父类的toString()会调子类的toString()一样。第一次调用getClass是me.exampleMethod(),虽然Subclass没有exampleMethod是继承来的,但是,你是用的显示调用,就是在Subclass中调用的,没问题;而第二次调用,虽然你是调用的Supeclass但是,返回的仍然是继承类的重载方法
SuprClass里的interestingMethod方法是private(那么Subclass里interestingMethod方法并没有覆盖父类)
所以在执行的interestingMethod方法的时候用的是invokeespecial指令
就不会再根据栈顶的实际类型来选在方法接受者了,也就执行不到子类的interestingMethod