blob: 1a35094a7db933ee12454ca0567f447b85ea6089 [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="s6.1.b.html" rel="prev">&lt;&lt;&nbsp;&sect;6.1.(b)&nbsp;Behavioral reflection</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="s6.html" rel="section">&sect;6&nbsp;Object Teams API</a>&nbsp;&gt;&nbsp;<a class="nav" href="s6.1.html" rel="section">&sect;6.1&nbsp;Reflection</a></div>
<div class="subsect depth3" id="s6.1.c">
<h4 class="subsect">&sect;6.1.(c)&nbsp;<span class="title">Class literals for roles</span><a class="img" href="s6.1.c.html"
title="PermaLink to (c)&nbsp;Class literals for roles"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>The Java syntax for so-called class literals, <code>MyClass<strong>.class</strong></code>
(see <a href="http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#251530"
class="ext">JLS &sect;15.8.2</a>)
can be used for role types with slightly changed semantics: Role types are virtual types (<a href="s1.3.1.html"
title="&sect;1.3.1&nbsp;Acquisition and implicit inheritance of role classes"
class="sect">&sect;1.3.1</a>)
that are bound dynamically (<a href="s1.3.1.e.html" title="&sect;1.3.1.(e)&nbsp;Dynamic binding of types"
class="sect">&sect;1.3.1.(e)</a>). This applies to role class literals, too.
From this follows the constraint that a role class literal can only be used within the non-static context of a team,
ie., for evaluating a role class literal an enclosing team instance must be in scope.
<br />
Unlike regular type checking for role types, the class literal itself does not have a dependent type.
Thus type checking of calls to methods like <code>hasRole(Object, Class)</code> cannot detect, whether the <code>Class</code> instance
has actually been obtained from the correct team instance. Any attempt to pass a class that is not known
as a bound role within the given team results in an <code>IllegalArgumentException</code> at run-time.
</p>
</div>
<table class="nav">
<tr>
<td class="back"><a href="s6.1.b.html" rel="prev">&lt;&lt;&nbsp;&sect;6.1.(b)&nbsp;Behavioral reflection</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="s6.html" rel="section">&sect;6&nbsp;Object Teams API</a>&nbsp;&gt;&nbsp;<a class="nav" href="s6.1.html" rel="section">&sect;6.1&nbsp;Reflection</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: 2011-05-15
</div>
</body>
</html>