Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8179311

Allow private members for interfaces

    XMLWordPrintable

Details

    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.


      Attachments

        Issue Links

          Activity

            People

              smarks Stuart Marks
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: