0

Why do we have to declare a field in a class or method to be final in java,

if it is to be accessed/used from an anonymous inner class?

Positive
  • 62
  • 5
  • You don't need that. The only thing you need are getters and setters (a very important way of manipulating field in Java, take a look !). Final means you will never be able to change its value. – Lutzi Apr 30 '18 at 12:52
  • 1
    Lutzi is correct. This restriction applies to local variables, not fields. – Stephen C Apr 30 '18 at 12:53
  • Also note that this is not needed anymore, it is enough if the local variable is effectively final. – AxelH Apr 30 '18 at 13:14

0 Answers0