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

Mutually recursive constructors could be flagged as warning or error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.1.2
    • tools
    • sparc
    • solaris_2.5.1

      If a class has two constructors that each call the other with this(...),
      this could be called an warning, because it is never possible for this to
      not throw an exception. (It will end with StackOverflowError, OutOfMemoryError, or if the argument evaluations throw any exception).

      While it may be reasonable to allow this for the side effects the argument evaluations could have, I believe a warning would make much more sense than
      saying nothing.


      Example code:

      public class ConCir {

        public ConCir(int a, double d){
      this(a,d,0);
        }

        public ConCir(int a, double d, int b){
      this(a,d);
        }

        public static void main(String[] args){
          new ConCir(0,0.0);
        }

      }

            wmaddoxsunw William Maddox (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: