我希望我的左花括号与声明的结尾位于同一行,包括一般的例外,即
void someMethod () throws Exception {
或
void someMethod ()
throws Exception {
而不是
void someMethod () throws Exception
{
但是,如果我想在Javadoc之外注释异常,则需要将大括号移动到下一行,以确保它没有被注释掉,并且它不会出现在大括号会使异常更难关联,所以我需要checkstyle来识别这个特例或提示我没看到的内容,例如
void someMethod() throws Exception
//that's ugly, fix later. The reason Exception is thrown is because of this
//very very very very very very very very very very very very very very very
//very very very very very very very very very very long reason that spans
//multiple lines
{
Javadoc之外的评论可能是对@throws
解释的补充,例如呼叫者不应该被打扰的事情。因为建议在可见的Javadoc中分享尽可能多的用例,所以很少有用例,但我也想扩大我对checkstyle的理解。
答案 0 :(得分:1)
就个人而言,我会考虑将关于异常的评论直接放在它下面 - 在左大括号之后:
void someMethod()
throws Exception {
// todo: that's ugly, fix later. The reason Exception is thrown is
// because of this very very very very very very very very very very
// very very very very very very very very very very very very very
// very very long reason that spans multiple lines.
你也可以重新考虑把它放在Javadoc中,或者你真的决心不把它放在那里吗?
另一种选择是使用SuppressWarnings
注释(在java.lang
中定义)在这种特殊情况下抑制Checkstyle警告:
@SuppressWarnings("checkstyle:leftcurly")
void someMethod()
throws Exception
// todo: that's ugly, fix later. The reason Exception is thrown is
// because of this very very very very very very very very very very
// very very very very very very very very very very very very very
// very very long reason that spans multiple lines.
{