java - 这是什么意思 : 'private' modifier out of order with the JLS suggestions

标签 java eclipse-plugin field warnings

在将“最终”添加到 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 节。

publicprivate 应该在 static 之前,它应该在 final 之前。

关于java - 这是什么意思 : 'private' modifier out of order with the JLS suggestions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34887278/

相关文章:

java - Android 中的简单 SharedPreferences

java - Java中的Gson、JsonElement、String比较

database - awk 和字段拆分参数

javascript - 如何使用javascript防止输入字段中出现空格和句号

java - 如何忽略 Transformer 格式化 xml Java

java - Java中的字符串初始化

java - 获取java文件之间的方法调用次数

java - 如何在 Eclipse 上安装插件

java - TreeViewer.expandAll 方法的性能

wordpress - 显示自定义类别的子类别 - WordPress