title: Improvement/s to my Java generic console input method?
body: <p>Using Java Generics, I tried to implement a generic console input method.</p>
  
  <pre><code>public static &lt;T&gt; T readFromInput(String message, Class&lt;?&gt; c) throws Exception{
          System.out.println(message);
          Scanner scanner = new Scanner(System.in);
          try {
              if(c == Integer.class)
                  return (T) Integer.valueOf(scanner.nextInt());
              if(c == String.class)
                  return (T) scanner.nextLine();
              if(c == Double.class)
                  return (T) Double.valueOf(scanner.nextDouble());
              if(c == Float.class)
                  return (T) Float.valueOf(scanner.nextFloat());
          } catch (InputMismatchException e) {
              throw new Exception(e);
          }
          return null;
      }
  </code></pre>
  
  <p>I'm having a warning "Type safety: Unchecked cast from Integer to T". Aside from @SuppressWarnings, is it possible to avoid this warning?</p>
  
  <p>Are there better ways to implement my method? Thanks in advance</p>