Details
-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
None
Description
A DESCRIPTION OF THE REQUEST :
Since Java 8 there are default implementations for interfaces, which is great. But I cannot define private static constants, private member fields or private methods to use from inside these default methods.
There's no obvious reason for not allowing this. I suggest to do it.
public interface I
{
public static final int foo = 1234;
private void help()
{
// Do some internal stuff.
}
public default void bar()
{
help();
// Do some basic stuff.
}
}
JUSTIFICATION :
I cannot write reusable, but internal code in an interface.
Since Java 8 there are default implementations for interfaces, which is great. But I cannot define private static constants, private member fields or private methods to use from inside these default methods.
There's no obvious reason for not allowing this. I suggest to do it.
public interface I
{
public static final int foo = 1234;
private void help()
{
// Do some internal stuff.
}
public default void bar()
{
help();
// Do some basic stuff.
}
}
JUSTIFICATION :
I cannot write reusable, but internal code in an interface.
Attachments
Issue Links
- duplicates
-
JDK-8072872 9.4: Allow interface methods to be 'private'
- Closed