3

I have simple class that contains inner class that according to my understanding uses effectively final variable f:

public class WithInner {

    public static void main (String [] args)
    {
        WithInner i = new WithInner();
    }

    interface LocalInterface
    {
        void iia();
    }

    public void aa()
    {
        int f = 20;
        LocalInterface i = new LocalInterface() {
            public void iia() {
                System.out.println(" "+f);
            }
        };
    }
}

But my Intellij IDE complains regarding f is not declared final:

local variable f is accessed from within inner class; needs to be declared final

But if the f variable is effectively final there is no need to declare it final, isn't that true?

UPD:

My project structure is configured to use Java 8:

enter image description here

vico
  • 17,051
  • 45
  • 159
  • 315

0 Answers0