what does this mean: 'private' modifier out of order with the JLS suggestions
Solution 1
For the first, it's just good practice to make things final
if they definitely don't change during their lifetime. This helps for reasoning about the mutability of your objects.
For the second warning you're looking for JLS sections 8.1.1, 8.3.1 and 8.4.1.
public
or private
should come before static
, which should come before final
.
Solution 2
The usual order is for private
to come before final
, like this:
private final Item myItem;
The code will still compile and behave the same if the modifiers are in a different order, but people who are used to the standard order suggested by the JLS will think your code looks weird.
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I first got this warning before adding 'final' to the myItem declaration:
Private field 'myItem' could be made final; it is only initialized in the declaration or constructor.
private Item myItem;
After adding final this is the warning i get:
'private' modifier out of order with the JLS suggestions.
final private Item myItem;
Does anyone know why I'm getting this? I've done some research but can't seem to find anything to solve this problem.