title: How to convert a string value to some concrete type?
body: <p>I have a string value and a class object of a concrete type.</p>
  
  <p>So my question is how to convert a string value to that type?<br>
  It really looks like the only possible way is to do something like this:</p>
  
  <pre><code>private Object convertTo(String value, Class type) {
      if(type == long.class || type == Long.class)
          return Long.valueOf(value);
      if(type == int.class || type == Integer.class)
          return Integer.valueOf(value);
      if(type == boolean.class || type == Boolean.class)
          return Boolean.valueOf(value);
      ...
      return value;
  }
  </code></pre>
  
  <p>But that looks ugly ... is there any nicer way to do that?</p>