title: Can a field of a Java class be of multiple types without using generics?
body: <p>I have a class, which's instances will be serialized. Thus the class implements <code>Serializable</code>. The class has a field of type <code>List</code>, which must be <code>Serializable</code> as well of course. Imagine the class looking something like this:</p>
  
  <pre><code>import java.io.Serializable;
  import java.util.List;
  
  public class Report implements Serializable {
  
      private static final long serialVersionUID = 12345L;
  
      private List&lt;Record&gt; records = new ArrayList&lt;&gt;();
  }
  </code></pre>
  
  <p>Now I know that <code>ArrayList</code> is <code>Serializable</code>, but I'd rather declare my field to be of some interface type.</p>
  
  <p>The issue comes when our SonarQube analyzes the code. It complains, that the field <code>records</code> should be of some <code>Serializable</code> type as well and SonarQube is right.</p>
  
  <p>But due to the fact that the field is an implementation detail (a private member), I don't want to use generics on the class.</p>
  
  <p>And here comes my question:
  With the self applied constraints to declare the field of some interface type and not use generics, is it possible to declare the field to be of multiple (interface) types?</p>
  
  <p>FYI: I know one can cast to multiple types, but that's something entirely different.</p>
  
  <pre><code>Object o = (List&lt;Serializable&gt; &amp; Serializable) new ArrayList&lt;Serializable&gt;();
  </code></pre>
  
  <p>The above is perfectly legal although unnecessary.</p>