title: How to generically specify a Serializable List
body: <p>I have the following interface:</p>
  
  <pre><code>public interface Result&lt;T extends Serializable&gt; extends Serializable{
      T getResult();
  }
  </code></pre>
  
  <p>With that interface, I can not define a variable of type</p>
  
  <pre><code>Result&lt;List&lt;Integer&gt;&gt;
  </code></pre>
  
  <p>because List is not serializable.</p>
  
  <p>However, if I change the interface to this:</p>
  
  <pre><code>public interface Result&lt;T&gt; extends Serializable{
      T getResult();
  }
  </code></pre>
  
  <p>It now becomes impossible to implement, with compile time checking, because there is no guarantee that T is serializable, and the whole point of the class is to store the result so that I can get it back later, possibly after a transfer over the internet.</p>
  
  <p>My question is this, is there a way to declare a variable so that it is of two types, or is there some other way to do this that I am not seeing?  So, maybe something like:</p>
  
  <pre><code>(List&lt;Integer&gt; extends Serializable) value = new ArrayList();
  </code></pre>
  
  <p>I am trying to put as much of the burden of this problem on the implementation, so that future consumers of this interface are unaware of the problem.</p>
  
  <p>Thanks for your help!</p>
  
  <p>Here is a more detailed example of what I am trying to do:
  I am calling a server, The result of which I want to store in a result object, but I do not want to have to deal with casting.  So, each method that can be called on the server will define the type of the result by using generics.  This result object will also store other meta-data about the result, for example maybe there was too much information to return.  In many cases I want to use a list, but the List interface is not serializable, although many of the implementations are.</p>
  
  <p>So, how to I specify that the type used must be Serializable, but still allow for a List(and not a specific implementation of List) to be used?</p>