title: Stack Overflow Error with toStrings() (java)
body: <p>Two of my toString()'s appear to be in an infinite loop, but I am unsure what the problem is. I have been debugging this for hours now and can't see anything that would be wrong.</p>
  
  <p>For context, the pertinent parts of the main are:
      System.out.println(class1);
      adminStaff1.assignInstructor(class1, instructor1);
      System.out.println(class1);</p>
  
  <p>The first println works, but when I debug I see one source lookup error before it goes through. The second class1 creates the StackOverflowError which is:</p>
  
  <pre><code>Exception in thread "main" java.lang.StackOverflowError
  at java.lang.AbstractStringBuilder.append(Unknown Source)
  at java.lang.StringBuilder.append(Unknown Source)
  at java.lang.StringBuilder.&lt;init&gt;(Unknown Source)
  at Instructor.toString(Instructor.java:59)
  at java.lang.String.valueOf(Unknown Source)
  at java.lang.StringBuilder.append(Unknown Source)
  at Class.toString(Class.java:89)
  at java.lang.String.valueOf(Unknown Source)
  at java.lang.StringBuilder.append(Unknown Source)
  at java.util.AbstractCollection.toString(Unknown Source)
  at java.lang.String.valueOf(Unknown Source)
  at java.lang.StringBuilder.append(Unknown Source)
  at Instructor.toString(Instructor.java:59)
  </code></pre>
  
  <p>The toString for Class is:</p>
  
  <pre><code>@Override
  public String toString() {
      return "Class [instructor=" + instructor + ", lectureHall="
              + lectureHall + ", currentEnrollment=" + currentEnrollment
              + ", timeSlot=" + timeSlot + ", filled=" + filled
              + ", studentList=" + studentList + "]";
  }
  </code></pre>
  
  <p>The toString for Instructor is:</p>
  
  <pre><code>@Override
  public String toString() {
      return "Instructor [salary=" + salary + ", classList=" + classList
              + ", openTimeSlots=" + openTimeSlots + ", "
              + super.toString() + "]";
  }
  </code></pre>
  
  <p>and the super.toString() is:</p>
  
  <pre><code>@Override
  public String toString() {
      return "[idNumber=" + idNumber + ", email=" + email
              + "]";
  }
  </code></pre>
  
  <p>I'm not sure why, but adminStaff1.assignInstructor also seems to be contributing to the problem, it is:</p>
  
  <pre><code>public void enrollStudent(Student student, Class aClass){
      aClass.checkIfFilled();
      if(!aClass.getFilled()){
          aClass.addStudent(student);
          student.addClass(aClass);
          aClass.increaseEnrollment();
      } else {
          System.out.println("Could not add student because the class is currently full.");
      }
  }
  </code></pre>
  
  <p>I sincerely appreciate if anyone can help me understand what is wrong. Thanks.</p>