title: How to get a class selected by the user?
body: <p>I had read some posts about it, but not sure if some is the answer that i've been looking for. I want to get a class selected by user input and check if it is on a list. I don't wanna create if, switch or Map (I'll use lots of classes). I'm trying to do this in few lines, if it's possible at all. Thanks!</p>
  
  <pre><code>public boolean isClassDefined(ArrayList&lt;GeometricObject&gt; geoObjects) {
      Class&lt;?&gt; classDefinedByUser=null;
      try {
          classDefinedByUser = Class.forName("Square");
          //as if user has typed "Square", being "class Square extends GeometricObject"
      } catch (ClassNotFoundException ex) {
          Logger.getLogger(Mission.class.getName()).log(Level.SEVERE, null, ex);
      }
  
      for (GeometricObject geo : geoObjects) {
          //here is where i don't know what to do
          //I want to create a if to check if there is an object (of the class
          //defined by the user) initialized into ArrayList "geoObjects"
          //I don't want to use lots of ifs
          if (geo instanceof classDefinedByUser.getClass()) {
              //if exists a Square type object, return true
              return true;
          }
      }
      return false;
  }
  </code></pre>