A method can be defined with the same name as constuctor of the class.

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 1.1.6
    • Component/s: tools
    • generic
    • generic



      Name: diC59631 Date: 11/11/98


      // the class
      public class MyClass {
          // the constructor
          public MyClass() {
              // do something
          }

          // the method with the same name as constructor
          public void MyClass() {
              // do something
          }
      }

      In other program, you can use the class like this:
          // call the constructor
          MyClass myclass = new MyClass();
          // call the method public void MyClass()
          myclass.MyClass();

      The java complier allows this kind of usage, but it
      looks confusing(It is not allowed in C++).

      If you forgot to implement the constructor(with a
      "void" before the method name), the code is also
      allowed. But the default constructor does nothing,
      so you maybe think it strange.

      I think the java complier should check this situation,
      and do not allow the method with the same name as
      the constructor.
      (Review ID: 42467)
      ======================================================================

            Assignee:
            Todd Turnidge (Inactive)
            Reporter:
            Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: