A bit more specific than Stack Overflow question What is an existential type?, what is the difference between Scala's existential types and Java's wildcard, prefereably with some illustrative example?
In everything I've seen so far, they seem to be pretty equivalent.
A few references. Martin Odersky mentions them; Google's top hit for my question:
MO: The original wildcard design ... was inspired by existential types. In fact the original paper had an encoding in existential types. But then when the actual final design came out in Java, this connection got lost a little bit
They are very similar but Scala's existential type is supposed to be more powerful. For example, Scala's existential type can be both upper and lower bounded whereas Java's wildcard can only be upper bonded.
For example, in Scala:
the foo takes a list of parameter that has a lower bound of Int.
This is Martin Odersky's answer on the Scala-users mailing list:
So it does seem that Scala existential types and Java wildcards are kind-of equivalent
The
List[_]
notation (which as other answers point out is a more powerful analog to Java'sList[?]
) is a degenerate case of the more general notion of an existential type in Scala.They are supposed to be equivalent, as their main purpose is interacting with Java's wildcards.
A way more detailed answer by Martin Odersky (the rest can be found here):