title: Passing HashMap as parameter into a subclass constructor
body: <p>I've been struggling with trying to figure out the problem and fixing the error when I tried to pass HashMap into a constructor. My scenario is:</p>
  <p>I've a Student class:</p>
  <pre><code>public class Student {
     String name;
     String major;
     String level;
     
     public Student (String name, String major, String level) {
        this.name = name;
        this.major = major;
        this.level = level;
     }    
  }
  </code></pre>
  <p>I've another class, called TA_Manager that is a subclass of Student. This TA_Manager class uses HashMap to collect the students (who are TA) from the Student class:</p>
  <pre><code>import java.util.HashMap;
  
  public class TA_Manager extends Student {
     HashMap&lt;String, Student&gt; TA;
     
     public TA_Manager(HashMap&lt;String, Student&gt; TA) {
        this.TA = TA;
     }
  }
  </code></pre>
  <p>In the main class, I've created three student objects and I put two of the students into the HashMap (they are TAs). Then I create a TA_Manager object and pass the HashMap into the TA_Manager class:</p>
  <pre><code>import java.util.HashMap;
  
  public class Test {   
     public static void main(String[] args) {
         Student s1 = new Student(&quot;A&quot;, &quot;CS&quot;, &quot;Junior&quot;);
         Student s2 = new Student(&quot;B&quot;, &quot;IS&quot;, &quot;Senior&quot;);
         Student s3 = new Student(&quot;C&quot;, &quot;CE&quot;, &quot;Senior&quot;);
  
         HashMap&lt;String, Student&gt; TA = new HashMap&lt;String, Student&gt;();       
         TA.put(&quot;TA1&quot;, s1);
         TA.put(&quot;TA2&quot;, s2);
  
         TA_Manager tamgr = new TA_Manager (TA);
     }
  }
  </code></pre>
  <p>When I run the main class, it returns error:
  TA_Manager.java:6: error: constructor Student in class Student cannot be applied to given types;
  public TA_Manager(HashMap&lt;String, Student&gt; TA) {
  ^
  required: String,String,String
  found:    no arguments</p>
  <p>I actually have searched this HashMap problem and I followed the solution given on how to pass the HashMap into the constructor:
  <a href="https://stackoverflow.com/questions/42709454/pass-a-hashmap-as-parameter-in-java">Pass a HashMap as parameter in Java</a>
  and also from this link on how to pass a class as hashmap value:
  <a href="https://stackoverflow.com/questions/23859041/can-hashmap-contain-custom-class-for-key-value">Can HashMap contain custom class for key/value?</a></p>
  <p>But I still get the error message. I don't know how to fix this error. Can anyone bring some light into this. Really appreciated.</p>