title: How to pass a .class-type parameter into a method
body: <pre><code>PersonenGenerator{
  Set&lt;Person&gt; personSet = new HashSet&lt;&gt;();
  
  public void printPersonTypeSet(Class clazz){ //pass a class that inherits from the class Person as a parameter
      for(Person instance : personSet){    
          if (instance instanceof clazz) System.out.println(instance);
      } // check if instance of Class Person are stored in personSet. If so, print said instance
  }
  
  
  public class Student extends Person{
  ...
  }
  public class Employee extends Person{
  ...
  }
  public class Main {
      public static void main(String[] args) {
          PersonenGenerator pg = new PersonenGenerator();
          pg.Student s1 = new Student(...);
          pg.personSet.add(s1);
          pg.Employee e1 = new Employee(...);
          pg.personSet.add(e1);
  
  
          printPersonTypeSet(Employee) //pass Employee as parameter SOMEHOW
      }
  }
  </code></pre>
  
  <p>EXPECTED BEHAVIOUR (Output): </p>
  
  <blockquote>
    <p>Employee{value1, value2, value3}</p>
  </blockquote>
  
  <p>My Compiler does not like the if-statement for some reason. Specifically where i call <code>clazz</code>.</p>
  
  <p>ACTUAL BEHAVIOR (Compiler Error) : </p>
  
  <blockquote>
    <p>Unknown Class:'clazz'</p>
  </blockquote>
  
  <p>My problem is that I intend to use <code>clazz</code> as a variable for instances of <code>Person</code>, while <code>Person</code> is the superclass for various subclasses.</p>
  
  <p>How do I keep the intended functionality and satisfy my compiler?
  First time doing this.</p>
  
  <p>EDIT: I feel like I've been misunderstood. I want to pass a class as the parameter under which the condition is checked. I commented the code to clarify this.</p>
  
  <p>If passing the parameter as type <code>Class</code> is bullshit for this, just say so. It was an idea, because I don't know how to pass a class as parameter.</p>