Java 8: Member Accessibility

Availability

Java 8 says:

All interface members without access modifiers are implicitly publicly

Java 7 says:

All interface members are implicitly public.

When I tried the following code:

public interface Test {
    protected int i = 10;
}

And compiled, I got

Test.java data: error: modifier protected not allowed here
        protected int i = 10;
                      ^

Java version: Java(TM) SE Runtime Environment (build 1.8.0-b129)

But in the member declaration, InterfaceI do not lack access modifier , then why I get this error.

+4
source share
3 answers

What do you quote in the JLS section in Defining Availability with Names

, ,

, , - ,

ConstantDeclaration:
    {ConstantModifier} UnannType VariableDeclaratorList ;
ConstantModifier:
    Annotation public 
    static final

public, static final. .

, , . , , , , public.

+7

, ", ". . .

0

9.3, 9.4 9.5 JLS 8 JLS 7:

, .

.

.

, , , " " 6.6.1, , public , . ( , - , .)

, . , -, 6.6.1, , . . , 9.3, 9.4 9.5 , 6.6.1 . , . , , , .

0

Source: https://habr.com/ru/post/1535080/


All Articles