Question regarding inheritance and any

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


trying some simple inheritance I tried

public class Valhalla {

   public static void main (String[] args) {

      List<int> intPoints = new ArrayList<>();


   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

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 Reimers

* Senior Expert Software Architect
* NetBeans Dream Team Member:
* Community Leader  NetBeans:
                              Desktop Java:
* JUG Leader JUG Bodensee:
* Duke's Choice Award Winner 2009
* Blog:

* LinkedIn:

Join the NetBeans Groups:
* LinkedIn:
* Oracle:

More information about the valhalla-dev mailing list