blob: 91d0ebc0662732beb63d889ad57d7aeac25371b7 [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></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"><a href="s9.2.html" rel="next">&sect;9.2&nbsp;Using classes with value parameters&nbsp;&gt;&gt;</a></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s9.html" rel="section">&sect;9&nbsp;Value Dependent Classes</a></div>
<div class="sect depth2" id="s9.1">
<h2 class="sect">&sect;9.1&nbsp;Defining classes with value parameters<a class="img" href="s9.1.html"
title="PermaLink to &sect;9.1&nbsp;Defining classes with value parameters"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h2>
<div class="syntaxlink"><a href="sA.html#sA.9.1" title="&sect;A.9.1&nbsp;TypeParameter" class="syntax">&rarr;&nbsp;Syntax&nbsp;&sect;A.9.1</a></div>
<div class="subsect depth3" id="s9.1.a">
<h4 class="subsect">(a)&nbsp;<span class="title">Value parameter declaration</span><a class="img" href="s9.1.a.html"
title="PermaLink to (a)&nbsp;Value parameter declaration"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>Within the angle brackets that mark the parameters of a generic class also value parameters
can be declared. In contrast to a type parameter, a value parameter is denoted as a pair
of two identifiers: a type and a free name, e.g.,
</p>
<div class="listing plain"><pre><b>class</b> MyClass<em>&lt;YourType aName&gt;</em> { ...</pre></div>
<p>Note that value parameters are valid for classes only, not for interfaces.
</p>
</div>
<div class="subsect depth3" id="s9.1.b">
<h4 class="subsect">(b)&nbsp;<span class="title">Value parameter application</span><a class="img" href="s9.1.b.html"
title="PermaLink to (b)&nbsp;Value parameter application"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>Within the given class (<code>MyClass</code>) the parameter name (<code>aName</code>) can be used
like a final field of the given type (<code>YourType</code>). In contrast to regular final fields
the assignment to this name occurs even before the constructor is executed.
</p>
</div>
<div class="subsect depth3" id="s9.1.c">
<h4 class="subsect">(c)&nbsp;<span class="title">Role types as dependent types</span><a class="img" href="s9.1.c.html"
title="PermaLink to (c)&nbsp;Role types as dependent types"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>Any role type can be interpreted as a value dependent type, however, in the declaration
of a role type the value parameter remains implicit: it is identical to the enclosing team instance.
</p>
</div>
</div>
<table class="nav">
<tr>
<td class="back"></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"><a href="s9.2.html" rel="next">&sect;9.2&nbsp;Using classes with value parameters&nbsp;&gt;&gt;</a></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s9.html" rel="section">&sect;9&nbsp;Value Dependent 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>