In my team we had a small discussion if a field declared 'private static final' in a class has any advantages from just declaring it 'private final'. For example if I have the following line in my class:
private static final String a = "a String";
Is this really better than just declaring it like this:
private final String a = "a String";
If it would be a variable that can be used outside of this class, declaring it static makes total sense. But as it is private I see no real advantage apart from a static variable being only created once and is than referenced in all objects. We have lots of tests and those define variables like this. Those tests are only run once when the system starts and are no longer needed after that. Apart from that is there anything I am missing?
finalwithoutstaticif the contents always stays the same. You're unnecessarily creating new objects. For aStringthis overhead is minimal because the actual text is interned, but if you ever create more complex objects in production code and 'forget' to make them static, you can get performance issues that you may not even be aware of. It's better to make it a habit to make them static.