title: Can we combine two methods that differ largely based on type?
body: <p>I have two similar, but of different types, blocks of code in Java:</p>
  
  <pre><code>private Integer readInteger() {
      Integer value = null;
      while (value == null) {
          if (scanner.hasNextInt()) {
              value = scanner.nextInt();
          } else {
              scanner.next();
          }
      }
  
      return value;
  }
  
  private Double readDouble() {
      Double value = null;
      while (value == null) {
          if (scanner.hasNextDouble()) {
              value = scanner.nextDouble();
          } else {
              scanner.next();
          }
      }
  
      return value;
  }
  </code></pre>
  
  <p>Is it possible to make just one method which would work for both of them? </p>