blob: f58e3a6234ff35c41c925ae7dfb611e6810a1c51 [file] [log] [blame]
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "../xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/ot.css" />
<link rel="stylesheet" type="text/css" href="../css/otjld.css" />
<title>OT/J Language Definition v1.3</title>
</head>
<body class="otdt">
<div id="content">
<table class="nav">
<tr>
<td class="back"><a id="top"></a><a href="s1.3.1.j.html" rel="prev">&lt;&lt;&nbsp;&sect;1.3.1.(j)&nbsp;Overriding and compatibility</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s1.html" rel="section">&sect;1&nbsp;Teams and Roles</a>&nbsp;&gt;&nbsp;<a class="nav" href="s1.3.html" rel="section">&sect;1.3&nbsp;Acquisition and implicit inheritance of role classes</a>&nbsp;&gt;&nbsp;<a class="nav" href="s1.3.1.html" rel="section">&sect;1.3.1&nbsp;Acquisition and implicit inheritance of role classes</a></div>
<div class="subsect depth4" id="s1.3.1.k">
<h4 class="subsect">&sect;1.3.1.(k)&nbsp;<span class="title">Covariant return types</span><a class="img" href="s1.3.1.k.html"
title="PermaLink to (k)&nbsp;Covariant return types"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>Given a team <code>T1</code> with two roles <code>R1</code> and <code>R2</code> where <code>R2</code> explicitly inherits from <code>R1</code>, both roles defining
a method <code>m</code> returning some type <code>A</code>.
Given also a sub-team of <code>T1</code>, <code>T2</code>, where <code>T2.R1</code> overrides <code>m</code> with a covariant return type <code>B</code>
(sub-type of <code>A</code>):
</p>
<div class="listing plain"><pre> <b>public</b> <b>team</b> <b>class</b> T1 {
<b>protected</b> <b>abstract</b> <b>class</b> R1 {
<b>abstract</b> A m();
}
<b>protected</b> <b>class</b> R2 <b>extends</b> R1 {
A m() { <b>return</b> <b>new</b> A(); }
}
}
<b>public</b> <b>team</b> <b>class</b> T2 <b>extends</b> T1 {
<b>protected</b> <b>class</b> R1 {
@Override B m() { <b>return</b> <b>new</b> B(); } <span class="error">// this declaration renders <b>class</b> T2.R2 illegal</span>
}
}</pre></div>
<p>
In this situation role <code>T2.R2</code> will be illegal unless also overriding <code>m</code> with a return type that is at least <code>B</code>.
Note, that the actual error occurs at the implicitly inherited method <code>T2.R2.m</code> which is not visible in the source code,
even <code>T2.R2</code> need not be mentioned explicitly in the source code.
A compiler should flag this as an imcompatibility at the team level, because a team must specialize inherited roles
in a consistent way.
</p>
</div>
<table class="nav">
<tr>
<td class="back"><a href="s1.3.1.j.html" rel="prev">&lt;&lt;&nbsp;&sect;1.3.1.(j)&nbsp;Overriding and compatibility</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s1.html" rel="section">&sect;1&nbsp;Teams and Roles</a>&nbsp;&gt;&nbsp;<a class="nav" href="s1.3.html" rel="section">&sect;1.3&nbsp;Acquisition and implicit inheritance of role classes</a>&nbsp;&gt;&nbsp;<a class="nav" href="s1.3.1.html" rel="section">&sect;1.3.1&nbsp;Acquisition and implicit inheritance of role classes</a></div>
</div>
<div id="footer">
<hr /><a class="w3c img" href="http://jigsaw.w3.org/css-validator/check/referer"
shape="rect"><img src="../images/valid-css2-blue.png" alt="Valid CSS!" height="31" width="88" /></a><a class="w3c img" href="http://validator.w3.org/check?uri=referer" shape="rect"><img src="../images/valid-xhtml10-blue.png" alt="Valid XHTML 1.0 Strict" height="31"
width="88" /></a><address>&copy; Stephan Herrmann, Christine Hundt, Marco Mosconi</address>
OT/J version 1.3 &mdash; last modified: 2010-06-08
</div>
</body>
</html>