《Thinking in java》——多態(1)

    If you call a dynamically-bound method inside a constructor, the overridden definition
that method is used. However, the effect of this call can be rather unexpected because th
overridden method will be called before the object is fully constructed. This can conceal
difficult-to-find bugs.

 

    (在子類中)如果你在構造方法中調用動態綁定的方法(父類中有的方法),就會調用到這個方法的重寫方法。然而,這種調用的效果是相當不被期望的,因爲重寫的方法會在對象完全構造之前被調用,這會掩蓋掉很難發現的bugs。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章