在方法签名之前放空格?

Sim*_*onT 4 java naming-conventions

我想知道对方法名称与其参数之间的空格的总体建议是什么。

即以下两行之间的一般偏好:

public static void main (String[] args) {} // (We'll ignore the question of spaces between the `String` and `[]` .)
public static void main(String[] args) {}
Run Code Online (Sandbox Code Playgroud)

我最近开始觉得前者更好,特别是考虑到方法声明中的所有其他内容(例如throws Exception(s)部分)也是空格分隔的。

sup*_*654 6

正如@chris 在评论中提到的,官方 Java 代码约定特别指出:

请注意,方法名称与其左括号之间不应使用空格。这有助于区分关键字和方法调用。

正如您在问题中可疑地考虑的那样,方法是故意不同的。