Subtyping in Java
In Java:
String
is a subtype ofObject
, because theString
class is a subclass of theObject
class.
int
is not a subtype ofObject
, because none of Java's primitive types are subtypes of any reference type.
StringBuilder
is not a subtype ofString
, because theStringBuilder
class is not a subclass of theString
class.
HashMap<Candidate,Double>
is a subtype ofMap<Candidate,Double>
, because theHashMap
class implements theMap
interface and the type parameters match.
HashMap<Candidate,Double>
is not a subtype ofMap<String,Ballot>
, even though theHashMap
class implements theMap
interface, because the type parameters do not match.