在将“最终”添加到 myItem 声明之前,我首先收到此警告:
Private field 'myItem' could be made final; it is only initialized in the declaration or constructor.
private Item myItem;
添加 final 后,这是我收到的警告:
'private' modifier out of order with the JLS suggestions.
final private Item myItem;
有人知道我为什么会收到这个吗? 我做了一些研究,但似乎找不到任何方法来解决这个问题。
最佳答案
首先,如果它们在其生命周期内绝对不会改变,那么将它们设为 final
只是一种很好的做法。这有助于推理对象的可变性。
对于第二个警告,您正在寻找 JLS第 8.1.1、8.3.1 和 8.4.1 节。
public
或 private
应该在 static
之前,它应该在 final
之前。
关于java - 这是什么意思 : 'private' modifier out of order with the JLS suggestions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34887278/