与How to change "Generate Method Stub" to throw NotImplementedException in VS?类似,但对于Eclipse而不是Visual Studio
NetBeans和Eclipse都有一个函数,如果您声明Java类来实现接口但省略一个或多个方法,则会自动为您生成存根方法。
区别在于Eclipse版本什么都不做,并返回零或null,例如
public String munge(String foo) {
// TODO Auto-generated method stub
return null;
}
NetBeans版本将引发异常:
public String munge(String foo) {
throw new UnsupportedOperationException("Not supported yet.");
}
我更喜欢。
是否可以配置Eclipse来执行此操作?
答案 0 :(得分:23)
转到Windows - >偏好 - > Java - >代码风格 - >代码模板。在右侧,您将看到“评论”和“代码”。展开“代码”,您正在寻找的是“方法主体”。点击“编辑...”并在其中放置您想要的任何内容。