假设不涉及 class 变量,在 Java 中使用私有静态方法比使用私有方法有什么优势

Assuming no class variables are involved, what are the advantages of using a private static method over a private method in Java

我能想到的一个优点是 防止在未来的增强 中意外更新 class 变量。我想知道还有没有其他的优势。

answer for C# 提到使用 static 方法时性能会有所提高。 Java 编译器是否也有类似的处理?

在我看来,private static 方法的主要用例是 public static 方法的重用和可读性。

可读性 假设您有一个包含许多分支的大型 public static 方法,那么让 private static 方法处理每个分支可能有助于提高可读性。这是 Clean Code 等书籍所提倡的方法。

再利用 假设您有许多具有重复代码的 public static 方法,那么将重复代码放在 private static 方法中通常是个好主意(当然,除非重复代码可用作实用方法它自己的权利)。