A DESCRIPTION OF THE REQUEST :
Java 8 provides the "default" keyword for interfaces, which is quite helpful; however, "default protected" is still flagged as an error. This does not make sense to me.
JUSTIFICATION :
I am working on an API that basically acts as an efficient proxy to user-selected APIs of similar function. A few of my interfaces have public default methods that could benefit by maintaining a reference to a piece of material that should be out-of-reach of the end user. The natural logic would be to use a protected method, in this case default protected.
I understand and support the forbidding of ordinary protected methods in an interface, that doesn't make any sense; but default protected should work if default does.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Default protected methods (by my reasoning) should provide material that has a default behavior, is overridable and accessible by implementing classes, and is invisible to the outside world (beyond the package). I.e., it cannot be called by any part of an application that implements an API built with it.
The majority of the usage would be for "default public" methods.
ACTUAL -
"default protected" is flagged as a syntax error by the compiler.
---------- BEGIN SOURCE ----------
public interface Example {
public default void publicMethod() {
Object o = protectedMethod();
System.out.println(o.getClass());
}
protected default Object protectedMethod() {
return new Object();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Usage of otherwise-unnecessary abstract classes do the job, but the application of default methods is somewhat crippled in cases like mine. I'm living in the days of Java 7 interfaces again, until "default protected" is available.
In my ideal, these abstractions would not exist, and I would cleanly implement some very simple methods in the interfaces. My code would be both cleaner and safer. I hope to see "default protected" implemented in the future.
Project is completable, but not ideal.
Java 8 provides the "default" keyword for interfaces, which is quite helpful; however, "default protected" is still flagged as an error. This does not make sense to me.
JUSTIFICATION :
I am working on an API that basically acts as an efficient proxy to user-selected APIs of similar function. A few of my interfaces have public default methods that could benefit by maintaining a reference to a piece of material that should be out-of-reach of the end user. The natural logic would be to use a protected method, in this case default protected.
I understand and support the forbidding of ordinary protected methods in an interface, that doesn't make any sense; but default protected should work if default does.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Default protected methods (by my reasoning) should provide material that has a default behavior, is overridable and accessible by implementing classes, and is invisible to the outside world (beyond the package). I.e., it cannot be called by any part of an application that implements an API built with it.
The majority of the usage would be for "default public" methods.
ACTUAL -
"default protected" is flagged as a syntax error by the compiler.
---------- BEGIN SOURCE ----------
public interface Example {
public default void publicMethod() {
Object o = protectedMethod();
System.out.println(o.getClass());
}
protected default Object protectedMethod() {
return new Object();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Usage of otherwise-unnecessary abstract classes do the job, but the application of default methods is somewhat crippled in cases like mine. I'm living in the days of Java 7 interfaces again, until "default protected" is available.
In my ideal, these abstractions would not exist, and I would cleanly implement some very simple methods in the interfaces. My code would be both cleaner and safer. I hope to see "default protected" implemented in the future.
Project is completable, but not ideal.