title: Java 8 compatibility issue: How to convert Object array to Subtype List in Java 8?
body: <p>So I had a program that worked fine on Java 7 but it fails to compile with an error in Java 8. So, I went through Java Compatibility issues and I think I found out the reason (Or did I? <a href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7144506" rel="nofollow noreferrer">http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7144506</a>) . I want to know if there's a short an efficient way to replicate what my original code snippet does with Java 8. Here's a program to represent the situation. In my code there's a setter method that does the job of populating the array and I have no control on how it's populated. </p>
  
  <pre><code>import java.util.List;
  import java.util.Arrays;
  
  public class HelloWorld{
      public static void main(String []args){
          B someObject=new B();
          List&lt;A&gt; a = someObject.getA() == null ? Collections.EMPTY_LIST : Arrays.asList(someObject.getA());
          for ( A item : a ) {
              System.out.println(item.value);
          }
      }
  }
  
  class A{
      String value;
      public A(String value){
          this.value = value;
      }
  }
  
  class B{
      Object[] getA(){
          Object arr[]= new Object[4];
          arr[0]=new A("hello");
          arr[1]=new A("mello");
          arr[2]=new A("jello");
          arr[3]=new A("cello");
          return arr;
      }
  }
  </code></pre>
  
  <p>The error of course being:</p>
  
  <pre><code>HelloWorld.java:8: error: incompatible types: bad type in conditional expression                                                                                                
          List&lt;A&gt; a = someObject.getA() == null ? Collections.EMPTY_LIST : Arrays.asList(someObject.getA());                                                                      
                                                                                        ^                                                                                         
      inference variable T has incompatible bounds                                                                                                                                
        equality constraints: A                                                                                                                                                   
        lower bounds: Object                                                                                                                                                      
    where T is a type-variable:                                                                                                                                                   
      T extends Object declared in method &lt;T&gt;asList(T...)                                                                                                                         
  Note: HelloWorld.java uses unchecked or unsafe operations.                                                                                                                      
  Note: Recompile with -Xlint:unchecked for details.                                                                                                                              
  1 error                     
  </code></pre>
  
  <p>I need a (preferrably one line/elegant) alternative method which is also efficient to accomplish the same.</p>
  
  <p><strong>EDIT:</strong> To clarify. I cannot control what class B returns to me. Nor can I modify class A in any way (I don't think that could help in any case). I can only control what HelloWorld does.</p>