I have a couple of questions about abstract with default implementation

bitter_fox bitterfoxc at gmail.com
Fri Dec 16 21:14:55 PST 2011


I have a couple of questions about abstract with default implementation

*Revision of javac is 1245.

1.Does "default implementation" work in extending abstract class?
interface A
{
    void a() default {}
}
interface B
{
    void a(); // B#a is an abstract method same as C#a
}
abstract class C
{
    public abstract void a();
}

class D implements A, B // OK
{}
class E extends C implements A // Compile error
{}

Is it correct that E makes the compile error:
Main.java:16: error: E is not abstract and does not override abstract
method a() in C
class E extends C implements A // Compile error

2.Can I use default implementation for "abstract method" in interface?
The methods are abstract in interface, whether there is "abstract" or not.
(I know that using "abstract" in interface is not recommended.)
So, these will be same:
interface A
{
    void a() default {}
}
interface B
{
    abstract void a() default {} // (1)
}
However, (1) makes the compile error:
Main.java:25: error: abstract methods cannot have a body
        abstract void a() default {} // (1)

Thanks,
bitter_fox


More information about the lambda-dev mailing list