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

8.8.10: Clarify that protected ctor may be used to instantiate (anonymous sub-)class

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      "A public class can likewise prevent the creation of instances outside its package by declaring at least one constructor, to prevent creation of a default constructor with public access, and by declaring no constructor that is public."

      This is incorrect: a public class with only a protected ctor can be instantiated outside the package.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A public class can likewise prevent the creation of instances outside its package by declaring at least one constructor, to prevent creation of a default constructor with public access, and by declaring no constructor that is public or protected.
      ACTUAL -
      A public class can likewise prevent the creation of instances outside its package by declaring at least one constructor, to prevent creation of a default constructor with public access, and by declaring no constructor that is public.

      URL OF FAULTY DOCUMENTATION :
      https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8.10

            abuckley Alex Buckley
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: