0

I understand the <? extends T> in Java is crudely equivalent to the existential qualifier (∃) but is <? super T> related to the universal qualifier (∀)?

Feel free to correct me if I'm wrong about ∃.

It's early and I'm confused, so may well be talking nonsense. I could buy that both are existential, as direction need not negate the logic for a "for some" relationship..?

Partially prompted by the fact that List[_] in Scala is described as existential and that's roughly the same as List<?> in Java.

Toby
  • 9,523
  • 8
  • 36
  • 59
  • 2
    I think I am missing something here - but how is extends T> similar to the existential qualifier? – LionC Oct 08 '14 at 07:58
  • 2
    I cannot see the relation between "exists" (∃), "for all..." (∀) and these keywords. This [answer](http://stackoverflow.com/a/4343547/1919228) explains quite clear what they mean: one allows going down in the class hierarchy and the other allows going up – Pablo Lozano Oct 08 '14 at 08:00
  • 1
    that is crazy-talk, quick take this cyanide! – user2504380 Oct 08 '14 at 08:01
  • 1
    It sort of makes sense, I'd opt to say `extends` is like floor and and `super` is like ceiling, but not really. – ChiefTwoPencils Oct 08 '14 at 08:01
  • If you want to read about the relation to Scala's existential types, Odersky explains it [on this page](http://www.artima.com/scalazine/articles/scalas_type_system.html). –  Oct 08 '14 at 08:37

3 Answers3

3

Wildcard types (both ? extends T and ? super T) form a subset of existential types. Both of these you can read like "there exists some type which (extends|is supertype of) T". The key idea is that you don't know exact type.

Universal types are just type parameters. For example, here:

class List<T> { ... }

T is arbitrary, like it has an implicit universal qualifier.

Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296
1

Its not really related to predicate logic, its related to the type hierachy. I can understand why you might read out loud <? extends T> as "For all T's" but its extended to "For all objects that have a super class of T" rather than "For all T in X" as in predicate logic.

Similarly <? super X> should be read as "For objects that are of a type that is a super class on X"

Elliott Hill
  • 941
  • 7
  • 14
0

The main difference between <? super T> and <? extends T> is that the first declaration says that some type is an ancestor of T and the second says that some type is a subclass of T. I don't see any correlation with existential qualifier or universal qualifier here. As someone noticed in the comments, the more likely similarity (if you really must have one) is type floor and ceiling. Nevertheless, it's really an abstract analogy.

Adam Sznajder
  • 9,108
  • 4
  • 39
  • 60