Why can't you declare member interfaces in a local class?

You cannot declare an interface inside a block as shown below

public void greetInEnglish() {

        interface HelloThere {
           public void greet();
        }

        class EnglishHelloThere implements HelloThere {
            public void greet() {
                System.out.println("Hello " + name);
            }
        }

        HelloThere myGreeting = new EnglishHelloThere();
        myGreeting.greet();
}

In This Oracle Tutorial, I Have "You Cannot Declare Member Interfaces in a Local Class". because "interfaces are inherently static."

I want to understand this with more rational information, why and how is the interface inherently static?

and why does the code above not make sense?

Thanks in advance for the collaboration!

+4
source share
3 answers

I want to understand this with more rational information, why and how is the interface inherently static?

because interfaces are implicitly static, and you cannot have non-final static in an inner class.

Why are they implicitly static?

.

?

- ,

:

- " ". , , Foo - , - Foo, Foo.

, - , , . - , , " " - , .

, - , , - ?

Java?

+2

, final. . - - .

, , .

. , .

0

, . , .

0

All Articles