title: Store class type as a variable to identify next expected object type in list in java
body: <p>I'm working on a project where I obtain a list of strings and need to parse them into objects of different types, for example I have <code>Command</code>, <code>FloatArgument</code> and <code>IntegerArgument</code> as 3 different classes. For a given input like "fetch 5 3.45" I need to see if it is correct and then get the arguments. For this I decided to ceate a sort of library where all commands can be stored in a hashlist</p>
  
  <pre><code>baseCommands = new HashMap&lt;String, Command&gt;();
  </code></pre>
  
  <p>In the command class I store basic information I need for each command and I'd also like to include the next expected token as for now I'm pretty sure for each command there is only going to be 1 type of token which can follow any command/argument. Therefor I created a <code>Class</code> field inside the command class as well as the argument classes which stores this information:</p>
  
  <pre><code>public class Command {
      public int identifier;
      public Class next;
      public boolean isLast;
  
      public Command(int identifier, Class next, boolean isLast) {
          //add the stuff neccesary to make general commands. (except string name).
          this.identifier = identifier;
          this.next = next;
          this.isLast = isLast;
      }
  }
  </code></pre>
  
  <p>Normally, as I understand it, if you would use an abstract class for storing different class types if they are all similar. For example an abstract class Animal is extended by <code>Dog</code>, <code>Cat</code>, etc. However in this case I have 2 separate things: Commands and Arguments. I feel like having an empty abstract class might not be the most elegant solution here, but I could be wrong.</p>
  
  <p>As I understand it the Class field is used to store class types. This would be ideal so that later I can see for a given token in an input if the next token after it matches the expected one by simply doing the following:</p>
  
  <pre><code>token.type instanceof lastToken.next
  </code></pre>
  
  <p>However once I try to put information into the hashmap like this: </p>
  
  <pre><code>baseCommands.put("execute", new Command(1, Command, false));
  </code></pre>
  
  <p>I get the following simple error: </p>
  
  <blockquote>
    <p>Command cannot be resolved to a variable</p>
  </blockquote>
  
  <p>Now I know that what it's trying to do is to pass a variable that doesn't exist instead of the class type like I'm trying to do. How can I pass the class Command as a type instead? Will I be able to use the above mentioned method of checking if the next token in the input is correct? Is this a correct way of doing this or should I create another abstract class for both commands and arguments?</p>
  
  <p>Thank you for your input.</p>