title: Avoiding many if statements - different datatypes
body: <p>I have many <code>if</code> statements and I want to avoid them. </p>
  
  <p>I tried with HashMap, but it did not work with datatypes. Please see the code below that I have. This is just the first <code>if</code> statement but I have more...
  field is a DataType</p>
  
  <pre><code>   if (field.equals(DataTypes.IntegerType)) {
       x = Integer.valueOf();
      } 
  
      [...]
  else if (field instanceof org.apache.spark.sql.types.TimestampType) {
    try {
      x = Timestamp.valueOf();
    } catch (Exception) {
      try {
        columns[i] = Timestamp.valueOf(...).toLocalDateTime());
      } catch (Exception) {
  
        throw new ParseException("...");
      }
    }
     [...]
  
  
      else {
      x = null
     }
  </code></pre>
  
  <p>Can I somehow avoid so many else <code>if</code> statements?</p>