title: Make a Java class generic, but only for two or three types
body: <p>(I was astonished not to be able to find this question already on stackoverflow, which I can only put down to poor googling on my part, by all means point out the duplicate...) </p>
  
  <p>Here is a toy class that returns the reverse of what you put into it. Currently it works on integers, but would require only very minor changes to work for String. </p>
  
  <pre><code>public class Mirror {
  
    int value;
  
    public int get() {
      return reverse(value);
    }
  
    private int reverse(int value2) {
      String valueString = value + "";
      String newString = reverse(valueString);
      return Integer.parseInt(newString);
    }
  
    private String reverse(String valueString) {
      String newString = "";
      for (char c : valueString.toCharArray()) {
        newString = c + newString;
      }
      return newString;
    }
  
    public void set(int value) {
      this.value = value;
    }
  
  }
  </code></pre>
  
  <p>What I'd like to do is make the class generic, but only for, say, two or three possible types. So what I want to write is: </p>
  
  <pre><code>public class Mirror&lt;X, where X is one of Integer, String, or MagicValue {
  
  X value
  
  public X get(){
  [...]
  </code></pre>
  
  <p>What's the correct syntax? My Google-fu is failing me... :( </p>
  
  <p>EDIT: it appears there <em>isn't</em> a correct syntax and it can't appear to be done, so my main question is: why? this seems like the sort of thing that people might want to do before they made the class <em>truly</em> generic...</p>
  
  <p>EDIT EDIT: Managed to work out the why with some labmates today, so added the relevant why answer below. </p>