Question about a feature in the Java 8 language.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about a feature in the Java 8 language.

Zachary1234-2
Consider the interface below:


package Test;

import static java.lang.System.*;

/*
Node that inclusion or omission
of the abstract keyword with the interface keyword
makes absolutely no different ever.
*/

abstract interface SomeInterface
{

    static String output()
    {
    return "output";
    }

    /*
    Why on earth can't things implementation
    interface method be labelled both default and static,
    even if they are and must be the same thing?
   
    Even if they won't remove this, they should
    allow both keywords to be present on the interface method.
    */
   
    //default
   
    static String otherOutput()
    {
    return "otherOutput";
    }
   
    default void doAction()            
    {
    out.println("doAction");
       
   
    }
   
}
//End of Interface here.

I can't log in to Oracle to access their forums.  My question is, given the presence of static imports at any rate, why is it that Java 8 interface methods marked static either

-don't have to be marked default and static
-or even can't be marked as default and static?




Reply | Threaded
Open this post in threaded view
|

Re: Question about a feature in the Java 8 language.

wadechandler
Administrator
There are definitely better places for this discussion, but the 2 concepts are very different, and not in the same ballpark.

One is a default instance method, which is polymorphic, and the other is a non-polymorphic class level method. Both those keywords on the same method really doesn't make any sense, and there would be no clear way to disambiguate the two between the compiler nor use as a developer.

Wade

On Aug 15, 2017 09:31, "Zachary1234" <[hidden email]> wrote:
Consider the interface below:


package Test;

import static java.lang.System.*;

/*
Node that inclusion or omission
of the abstract keyword with the interface keyword
makes absolutely no different ever.
*/

abstract interface SomeInterface
{

    static String output()
    {
    return "output";
    }

    /*
    Why on earth can't things implementation
    interface method be labelled both default and static,
    even if they are and must be the same thing?

    Even if they won't remove this, they should
    allow both keywords to be present on the interface method.
    */

    //default

    static String otherOutput()
    {
    return "otherOutput";
    }

    default void doAction()
    {
    out.println("doAction");


    }

}
//End of Interface here.

I can't log in to Oracle to access their forums.  My question is, given the presence of static imports at any rate, why is it that Java 8 interface methods marked static either

-don't have to be marked default and static
-or even can't be marked as default and static?





====================
Wade Chandler

Software Engineer
NetBeans and Open Source Contributor