Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Subtyping
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Java=== In Java, '''is-a''' relation between the type parameters of one class or interface and the type parameters of another are determined by the extends and [[Interface (Java)|implements]] clauses. Using the {{code|Collections}} classes, {{code|ArrayList<E>}} implements {{code|List<E>}}, and {{code|List<E>}} extends {{code|Collection<E>}}. So {{code|ArrayList<String>}} is a subtype of {{code|List<String>}}, which is a subtype of {{code|Collection<String>}}. The subtyping relationship is preserved between the types automatically. When defining an interface, {{code|PayloadList}}, that associates an optional value of [[generic type]] P with each element, its declaration might look like: <syntaxhighlight lang=java> interface PayloadList<E, P> extends List<E> { void setPayload(int index, P val); ... } </syntaxhighlight> The following parameterizations of PayloadList are subtypes of {{code|List<String>}}: <syntaxhighlight lang=java> PayloadList<String, String> PayloadList<String, Integer> PayloadList<String, Exception> </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)