小编Mat*_*att的帖子

如何压缩这些return语句或一起避免checkstyle错误?

目前,我正在为Java类编写打砖块游戏类。我对我的public javafx.scene.paint.Color getColor()方法遇到的一个检查样式错误有疑问,该方法根据被球击中的次数获取砖的颜色。

checkstyle错误说:Return count is 6 (max allowed for non-void methods/lambdas is 2).我认为这意味着我只能有2条返回语句,而我目前只有6条。所有的语句都有不同的返回值,基于这些值this.hits我不了解。其文档如下:

public javafx.scene.paint.Color getColor()

The current color to represent this Brick's breakability state.
Returns:There are five possible Colors that can be returned based on 
theBrick's current strength: Color.BLACK if this Brick cannot be 
broken;Color.WHITE if this Brick has been completely broken; and 
Color.RED, Color.YELLOW,Color.GREEN if this Brick will break after 1, 2, 
and 3 more hits, consecutively.
Run Code Online (Sandbox Code Playgroud)

和代码:

public javafx.scene.paint.Color getColor() …
Run Code Online (Sandbox Code Playgroud)

java javafx return checkstyle

3
推荐指数
2
解决办法
92
查看次数

标签 统计

checkstyle ×1

java ×1

javafx ×1

return ×1