Question regarding inheritance and any

Sven Reimers sven.reimers at gmail.com
Wed Jan 7 22:33:27 UTC 2015


Hi,

trying some simple inheritance I tried

public class Valhalla {

   public static void main (String[] args) {

      List<int> intPoints = new ArrayList<>();
      System.out.println(intPoints);

   }

   public static interface List<any T> { }

   public static class ArrayList<any T> implements List<T> { }

}

If I remove the any from the ArrayList<any T> I get the following compile
error:

incompatible types: cannot infer type arguments for ArrayList<>
      List<int> intPoints = new ArrayList<>();
                                         ^
    reason: no instance(s) of type variable(s) T exist so that ArrayList<T>
conforms to List<int>
  where T is a type-variable:
    T extends Object declared in class ArrayList
1 error

Having given this failure some thought I am now thinking this is
intentional so that every implementation of an anyfied super
class/interface has to actively opt in to provide support for anyfied types.

Is this the intention?

Thanks for clarifying and your patience answering all those questions...

-Sven

-- 
Sven Reimers

* Senior Expert Software Architect
* NetBeans Dream Team Member: http://dreamteam.netbeans.org
* Community Leader  NetBeans: http://community.java.net/netbeans
                              Desktop Java:
http://community.java.net/javadesktop
* JUG Leader JUG Bodensee: http://www.jug-bodensee.de
* Duke's Choice Award Winner 2009
* Blog: https://www.java.net//blog/sven

* XING: https://www.xing.com/profile/Sven_Reimers8
* LinkedIn: http://www.linkedin.com/in/svenreimers

Join the NetBeans Groups:
* XING: http://www.xing.com/group-20148.82db20
* NUGM: http://haug-server.dyndns.org/display/NUGM/Home
* LinkedIn: http://www.linkedin.com/groups?gid=1860468
                   http://www.linkedin.com/groups?gid=107402
                   http://www.linkedin.com/groups?gid=1684717
* Oracle: https://mix.oracle.com/groups/18497


More information about the valhalla-dev mailing list