title: Can a switch statement be used to determine the class of an object?
body: <p>After searching SO and the web, I've yet to come up with an answer for this in Java. It's pretty simple.</p>
  
  <p>I've got abstract class ParentClass. Class X and class Y both inherit from ParentClass. I've also got class <code>DataInputDialog extends JDialog</code>, which is meant to provide a user interface for entering data into class X and class Y instances. DataInputDialog class looks like below:</p>
  
  <pre><code>public class DataInputDialog extends JDialog {
  
      public DataInputDialog(ParentClass xOrY) {
          //calls super constructor, makes basic components such as
          //  buttons and panels that are used in either X or Y data entry
  
      }
  }
  </code></pre>
  
  <p>now I'd like to have a <code>switch</code> statement that would determine what type of <code>ParentClass</code> was passed to <code>DataInputDialog</code>. However, I've got no clue how to accomplish that. I've tried:</p>
  
  <pre><code>switch (xOrY.getClass().getTypeName()) {
      case X.class.getTypeName();
  }
  </code></pre>
  
  <p>and a couple other variations, but it always comes up with an error on the case statement saying either: it has to be a constant String, or that it cannot be converted to an integer.</p>
  
  <p>How do I get this switch statement to determine if <code>xOrY</code> is an instance of <code>X</code> or <code>Y</code>?</p>