Modifier order for 'default' (was: RFR: 8136583: Core libraries should use blessed modifier order)

Martin Buchholz martinrb at google.com
Wed Sep 16 17:25:09 UTC 2015


So although default "looks like" a modifier, technically it's not, but it
can be inferred from values of other modifiers.  Method.isDefault:

    public boolean isDefault() {
        // Default methods are public non-abstract instance methods
        // declared in an interface.
        return ((getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC |
Modifier.STATIC)) ==
                Modifier.PUBLIC) && getDeclaringClass().isInterface();
    }

In practice, it's reasonable to insist that "default" comes first - it's a
pseudo-modifier.  The JLS could bless that (maybe it already does?)


On Wed, Sep 16, 2015 at 4:34 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:

> Hi Bernd,
>
> In some respects “default” is easy. It can only occur on non-abstract
> methods on interfaces, and declaring such methods “public” is redundant (as
> is the case for abstract methods on interfaces, where also declaring
> “abstract” is redundant). [*] And there are more redundant cases related to
> enums and nested classes.
>
> A further clean up would to run relevant code inspections in the IDE to
> remove redundant declarations.
>
> Paul.
>
> [*] FWIW there are a few cases of “public default” and “default public” in
> the OpenJDK source code
>
> On 16 Sep 2015, at 04:48, ecki at zusammenkunft.net wrote:
>
> > Martin, this will be known as the "blame martin" patch, good work.
> >
> > But more seriously a minor thing I noticed in your shell script (as well
> as the mentioned sources and some coding guidelines), the new interface
> `default` method modifier is not defined in any of those lists.
> >
> > Not sure if it is actually a problem for this patch (there seems to be
> no line with default modifier), but its just a general observation (with
> the hidden hope to get an authoritative consensus of the location of
> `default` as well, even when it might be the wrong mailinglist).
> >
> > Greetings
> > Bernd
> > --
> > http://bernd.eckenfels.net
> >
> > -----Original Message-----
> > From: Martin Buchholz <martinrb at google.com>
> > To: core-libs-dev <core-libs-dev at openjdk.java.net>, Chris Hegarty <
> chris.hegarty at oracle.com>, Paul Sandoz <paul.sandoz at oracle.com>
> > Sent: Mi., 16 Sep. 2015 2:54
> > Subject: RFR: 8136583: Core libraries should use blessed modifier order
> >
> > Hi, Chris and Paul,
> > I'd like you to do a very boring code review.
> >
> > This change is entirely machine generated. (the script is more
> interesting)
> >
> http://cr.openjdk.java.net/~martin/webrevs/openjdk9/blessed-modifier-order/blessed-modifier-order.patch
> > https://bugs.openjdk.java.net/browse/JDK-8136583
>
>



More information about the core-libs-dev mailing list