我有一個被覆蓋的方法,在此方法中super用於調用被覆蓋的方法。然而,這個方法中的代碼是我在幾個類中使用的,我想通過將它們放到一個類中的單個方法中來重用此代碼。但由於此代碼使用關鍵字super,所以我不確定如何將重寫的方法的引用傳遞給我的新方法。例如,原來這裏是方法的Class1 INC:Java:將代碼移到另一個類後調用超級代碼
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
/* Lots of code goes here, followed by the super call */
return super.onOptionsItemSelected(item);
}
在等級2:
public boolean onOptionsItemSelected(MenuItem item)
{
/* Code from class1 gets relocated here. But how do I call super on the original method? */
}
[代表](http://en.wikipedia.org/wiki/Delegation_pattern) – alphazero