2016-12-30 70 views

回答

0

我假設你有一個interface MyInterface,它聲明方法void aMethod()class ImplementingClass implements MyInterface,並且你想知道實現aMethod()的語法。

使用的Xtend的ProposalProviderEclipse中提供要麼實現未實現的方法或者使ImplementingClass抽象。

Xtend's ProposalPRovider in Eclipse.

使用添加未實現的方法建議重寫方法會爲你自動生成。 ImplementingClass則是這樣的:

class ImplementingClass implements MyInterface { 

    override aMethod() { 
     throw new UnsupportedOperationException("TODO: auto-generated method stub") 
    } 

} 

正如你所看到的,擁有的Xtend一個特殊的關鍵字overrides定義覆蓋的其他方法的方法。它被用來代替常規的def關鍵字來定義方法。

只需刪除throw ...表達式並執行moethod即可。