blob: 3d223a8d3fe5542109480a6908f3669f1939f8b3 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 1.5.5">
<meta name="author" content="2019-08-08 13:15:33 CEST">
<title>N4JS Language Specification</title>
<link rel="stylesheet" href="styles/spec.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<!-- ************* docinfo ******************************************************************* -->
<!-- ************* Favicon ************-->
<link rel="icon" href="images/favicon.ico" />
<!-- ************* Back-to-top JQuery ************* -->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<link href="styles/prism.min.css" rel="stylesheet" />
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<!-- ************* Styles ************* -->
<link rel="stylesheet" type="text/css" href="styles/n4jsspec-adoc.css">
<!-- ****************** NavBar ****************** -->
<div id="menubar">
<div class="banner">
<a href="https://www.eclipse.org/n4js/#"><img id="logo" src="images/n4js-logo.png" alt="Eclipse N4JS"></a>
</div>
<ul>
<li><a href="index.html">Index</a></li>
</ul>
</div>
<!-- ************* docinfo ******************************************************************* -->
<style>
.admonitionblock td.icon .icon-todo:before{content:"\f249";color:#f4ee42}
</style>
</head>
<body class="book toc2 toc-left">
<div id="header">
<h1>N4JS Language Specification</h1>
<div class="details">
<span id="author" class="author">2019-08-08 13:15:33 CEST</span><br>
<span id="revnumber">version 0.9</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="introduction.html#_introduction">1. Introduction</a>
<ul class="sectlevel2">
<li><a href="introduction.html#_notation">1.1. Notation</a>
<ul class="sectlevel3">
<li><a href="introduction.html#_grammar-notation">1.1.1. Grammar Notation</a></li>
<li><a href="introduction.html#_type-judgments-and-rules-and-constraints-notation">1.1.2. Type Judgments and Rules and Constraints Notation</a>
<ul class="sectlevel4">
<li><a href="introduction.html#_typing-rules-and-judgments">1.1.2.1. Typing Rules and Judgments</a></li>
<li><a href="introduction.html#_types-of-an-element">1.1.2.2. Types of an Element</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="introduction.html#_auxiliary-functions">1.2. Auxiliary Functions</a>
<ul class="sectlevel3">
<li><a href="introduction.html#_binding">1.2.1. Binding</a></li>
<li><a href="introduction.html#_merging-types">1.2.2. Merging Types</a>
<ul class="sectlevel4">
<li><a href="introduction.html#_logic-formulas">1.2.2.1. Logic Formulas</a></li>
</ul>
</li>
<li><a href="introduction.html#_symbols-and-font-convention">1.2.3. Symbols and Font Convention</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="grammar.html#_grammar">2. Grammar</a>
<ul class="sectlevel2">
<li><a href="grammar.html#_lexical-conventions">2.1. Lexical Conventions</a>
<ul class="sectlevel3">
<li><a href="grammar.html#_identifier-names-and-identifiers">2.1.1. Identifier Names and Identifiers</a></li>
<li><a href="grammar.html#_this-keyword">2.1.2. This Keyword</a></li>
<li><a href="grammar.html#_regular-expression-literals">2.1.3. Regular Expression Literals</a></li>
<li><a href="grammar.html#_automatic-semicolon-insertion">2.1.4. Automatic Semicolon Insertion</a></li>
<li><a href="grammar.html#_jsdoc">2.1.5. JSDoc</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="names.html#_names">3. Names</a>
<ul class="sectlevel2">
<li><a href="names.html#_access-control">3.1. Access Control</a></li>
<li><a href="names.html#_accessibility-of-types-top-level-variables-and-function-declarations">3.2. Accessibility of Types, Top-Level Variables and Function Declarations</a>
<ul class="sectlevel3">
<li><a href="names.html#_accessibility-of-members">3.2.1. Accessibility of Members</a></li>
<li><a href="names.html#_valid-names">3.2.2. Valid Names</a></li>
<li><a href="names.html#_qualified-names">3.2.3. Qualified Names</a></li>
<li><a href="names.html#_name-duplicates">3.2.4. Name Duplicates</a>
<ul class="sectlevel4">
<li><a href="names.html#_lexical-environment">3.2.4.1. Lexical Environment</a></li>
<li><a href="names.html#_duplicates-and-shadowing">3.2.4.2. Duplicates and Shadowing</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="types.html#_types">4. Types</a>
<ul class="sectlevel2">
<li><a href="types.html#_overview">4.1. Overview</a></li>
<li><a href="types.html#_type-expressions">4.2. Type Expressions</a>
<ul class="sectlevel3">
<li><a href="types.html#_syntax">4.2.1. Syntax</a></li>
<li><a href="types.html#_properties">4.2.2. Properties</a></li>
<li><a href="types.html#_semantics">4.2.3. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_type-inference">4.3. Type Inference</a></li>
<li><a href="types.html#_generic-and-parameterized-types">4.4. Generic and Parameterized Types</a>
<ul class="sectlevel3">
<li><a href="types.html#_generic-types">4.4.1. Generic Types</a></li>
<li><a href="types.html#_type-variables">4.4.2. Type Variables</a></li>
<li><a href="types.html#_parameterized-types">4.4.3. Parameterized Types</a></li>
</ul>
</li>
<li><a href="types.html#_primitive-ecmascript-types">4.5. Primitive ECMAScript Types</a>
<ul class="sectlevel3">
<li><a href="types.html#_undefined-type">4.5.1. Undefined Type</a></li>
<li><a href="types.html#_null-type">4.5.2. Null Type</a></li>
<li><a href="types.html#_primitive-boolean-type">4.5.3. Primitive Boolean Type</a></li>
<li><a href="types.html#_primitive-string-type">4.5.4. Primitive String Type</a></li>
<li><a href="types.html#_primitive-number-type">4.5.5. Primitive Number Type</a></li>
<li><a href="types.html#_primitive-type-int">4.5.6. Primitive Type int</a></li>
<li><a href="types.html#_primitive-symbol-type">4.5.7. Primitive Symbol Type</a></li>
</ul>
</li>
<li><a href="types.html#_primitive-n4js-types">4.6. Primitive N4JS Types</a>
<ul class="sectlevel3">
<li><a href="types.html#_any-type">4.6.1. Any Type</a>
<ul class="sectlevel4">
<li><a href="types.html#any-type-semantics">4.6.1.1. Semantics</a></li>
<li><a href="types.html#any-type-type-inference">4.6.1.2. Type Inference</a>
<ul class="sectlevel5">
<li><a href="types.html#_default-type-of-variables">4.6.1.2.1. Default Type of Variables</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="types.html#_void-type">4.6.2. Void Type</a>
<ul class="sectlevel4">
<li><a href="types.html#void-type-semantics">4.6.2.1. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_unknown-type">4.6.3. Unknown Type</a></li>
<li><a href="types.html#_primitive-pathselector-and-i18nkey">4.6.4. Primitive Pathselector and I18nKey</a>
<ul class="sectlevel4">
<li><a href="types.html#pathselector-semantics">4.6.4.1. Semantics</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="types.html#_built-in-ecmascript-object-types">4.7. Built-in ECMAScript Object Types</a>
<ul class="sectlevel3">
<li><a href="types.html#ECMAScript-objects-semantics">4.7.1. Semantics</a></li>
<li><a href="types.html#_object-type">4.7.2. Object Type</a></li>
<li><a href="types.html#_function-object-type">4.7.3. Function-Object-Type</a></li>
<li><a href="types.html#_array-object-type">4.7.4. Array Object Type</a></li>
<li><a href="types.html#_string-object-type">4.7.5. String Object Type</a></li>
<li><a href="types.html#_boolean-object-type">4.7.6. Boolean Object Type</a></li>
<li><a href="types.html#_number-object-type">4.7.7. Number Object Type</a></li>
<li><a href="types.html#_global-object-type">4.7.8. Global Object Type</a></li>
<li><a href="types.html#_symbol">4.7.9. Symbol</a></li>
<li><a href="types.html#_promise">4.7.10. Promise</a></li>
<li><a href="types.html#_iterator-interface">4.7.11. Iterator Interface</a></li>
<li><a href="types.html#_iterable-interface">4.7.12. Iterable Interface</a></li>
</ul>
</li>
<li><a href="types.html#_built-in-n4js-types">4.8. Built-In N4JS Types</a>
<ul class="sectlevel3">
<li><a href="types.html#_n4object">4.8.1. N4Object</a>
<ul class="sectlevel4">
<li><a href="types.html#N4Object-semantics">4.8.1.1. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_n4class">4.8.2. N4Class</a></li>
<li><a href="types.html#IterableN">4.8.3. IterableN</a></li>
</ul>
</li>
<li><a href="types.html#_type-modifiers">4.9. Type Modifiers</a>
<ul class="sectlevel3">
<li><a href="types.html#Type_Modifiers_Dynamic">4.9.1. Dynamic</a></li>
<li><a href="types.html#_optional-return-types">4.9.2. Optional Return Types</a></li>
</ul>
</li>
<li><a href="types.html#_union-and-intersection-type-composed-types">4.10. Union and Intersection Type (Composed Types)</a>
<ul class="sectlevel3">
<li><a href="types.html#_union-type">4.10.1. Union Type</a>
<ul class="sectlevel4">
<li><a href="types.html#union-type-syntax">4.10.1.1. Syntax</a></li>
<li><a href="types.html#union-type-semantics">4.10.1.2. Semantics</a></li>
<li><a href="types.html#_warnings">4.10.1.3. Warnings</a></li>
</ul>
</li>
<li><a href="types.html#_intersection-type">4.10.2. Intersection Type</a>
<ul class="sectlevel4">
<li><a href="types.html#intersection-type-syntax">4.10.2.1. Syntax</a></li>
<li><a href="types.html#intersection-type-semantics">4.10.2.2. Semantics</a></li>
<li><a href="types.html#_warnings-2">4.10.2.3. Warnings</a></li>
</ul>
</li>
<li><a href="types.html#_composed-types-in-wildcards">4.10.3. Composed Types in Wildcards</a></li>
<li><a href="types.html#_property-access-for-composed-types">4.10.4. Property Access for Composed Types</a>
<ul class="sectlevel4">
<li><a href="types.html#_properties-of-union-type">4.10.4.1. Properties of Union Type</a>
<ul class="sectlevel5">
<li><a href="types.html#_remarks-on-union-type-s-members">4.10.4.1.1. Remarks on union type’s members:</a></li>
</ul>
</li>
<li><a href="types.html#_properties-of-intersection-type">4.10.4.2. Properties of Intersection Type</a>
<ul class="sectlevel5">
<li><a href="types.html#_remarks-on-intersection-type-s-methods">4.10.4.2.1. Remarks on intersection type’s methods:</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="types.html#_constructor-and-classifier-type">4.11. Constructor and Classifier Type</a>
<ul class="sectlevel3">
<li><a href="types.html#_syntax-3">4.11.1. Syntax</a></li>
<li><a href="types.html#_semantics-2">4.11.2. Semantics</a></li>
<li><a href="types.html#_constructors-and-prototypes-in-ecmascript-2015">4.11.3. Constructors and Prototypes in ECMAScript 2015</a></li>
</ul>
</li>
<li><a href="types.html#_this-type">4.12. This Type</a>
<ul class="sectlevel3">
<li><a href="types.html#this-type-syntax">4.12.1. Syntax</a></li>
<li><a href="types.html#this-keyword-semantics">4.12.2. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_enums">4.13. Enums</a>
<ul class="sectlevel3">
<li><a href="types.html#_enums-n4js">4.13.1. Enums (N4JS)</a>
<ul class="sectlevel4">
<li><a href="types.html#enums-syntax">4.13.1.1. Syntax</a></li>
<li><a href="types.html#enums-semantics">4.13.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_string-based-enums">4.13.2. String-Based Enums</a></li>
</ul>
</li>
<li><a href="types.html#_short-hand-syntax">4.14. Short-Hand Syntax</a>
<ul class="sectlevel3">
<li><a href="types.html#_array-short-hand-syntax">4.14.1. Array Short-Hand Syntax</a></li>
<li><a href="types.html#_iterablen-short-hand-syntax">4.14.2. IterableN Short-Hand Syntax</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_classifiers">5. Classifiers</a>
<ul class="sectlevel2">
<li><a href="#_n4js-specific-classifiers">5.1. N4JS Specific Classifiers</a>
<ul class="sectlevel3">
<li><a href="#_properties-2">5.1.1. Properties</a></li>
<li><a href="#_common-semantics-of-classifiers">5.1.2. Common Semantics of Classifiers</a></li>
<li><a href="#_classes">5.1.3. Classes</a>
<ul class="sectlevel4">
<li><a href="#_definition-of-classes">5.1.3.1. Definition of Classes</a>
<ul class="sectlevel5">
<li><a href="#class-syntax">5.1.3.1.1. Syntax</a></li>
<li><a href="#class-properties">5.1.3.1.2. Properties</a></li>
<li><a href="#class-type-inference">5.1.3.1.3. Type Inference</a></li>
</ul>
</li>
<li><a href="#class-semantics">5.1.3.2. Semantics</a></li>
<li><a href="#_final-modifier">5.1.3.3. Final Modifier</a></li>
<li><a href="#_abstract-classes">5.1.3.4. Abstract Classes</a></li>
<li><a href="#_non-instantiable-classes">5.1.3.5. Non-Instantiable Classes</a></li>
<li><a href="#_superclass">5.1.3.6. Superclass</a></li>
</ul>
</li>
<li><a href="#_interfaces">5.1.4. Interfaces</a>
<ul class="sectlevel4">
<li><a href="#_definition-of-interfaces">5.1.4.1. Definition of Interfaces</a>
<ul class="sectlevel5">
<li><a href="#interfaces-syntax">5.1.4.1.1. Syntax</a></li>
<li><a href="#interfaces-properties">5.1.4.1.2. Properties</a></li>
<li><a href="#interfaces-type-inference">5.1.4.1.3. Type Inference</a></li>
<li><a href="#interfaces-semantics">5.1.4.1.4. Semantics</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_generic-classifiers">5.1.5. Generic Classifiers</a></li>
<li><a href="#sec:definition-site-variance">5.1.6. Definition-Site Variance</a></li>
</ul>
</li>
<li><a href="#_members">5.2. Members</a>
<ul class="sectlevel3">
<li><a href="#_syntax-4">5.2.1. Syntax</a>
<ul class="sectlevel4">
<li><a href="#_properties-3">5.2.1.1. Properties</a></li>
</ul>
</li>
<li><a href="#_semantics-3">5.2.2. Semantics</a></li>
<li><a href="#_methods">5.2.3. Methods</a>
<ul class="sectlevel4">
<li><a href="#_syntax-5">5.2.3.1. Syntax</a></li>
<li><a href="#_properties-4">5.2.3.2. Properties</a></li>
<li><a href="#_semantics-4">5.2.3.3. Semantics</a></li>
<li><a href="#_final-methods">5.2.3.4. Final Methods</a></li>
<li><a href="#_abstract-methods">5.2.3.5. Abstract Methods</a></li>
<li><a href="#_generic-methods">5.2.3.6. Generic Methods</a></li>
</ul>
</li>
<li><a href="#_default-methods-in-interfaces">5.2.4. Default Methods in Interfaces</a>
<ul class="sectlevel4">
<li><a href="#_asynchronous-methods">5.2.4.1. Asynchronous Methods</a></li>
</ul>
</li>
<li><a href="#_constructors">5.2.5. Constructors</a>
<ul class="sectlevel4">
<li><a href="#_structural-this-type-in-constructor">5.2.5.1. Structural This Type in Constructor</a></li>
<li><a href="#spec-constructor">5.2.5.2. @Spec Constructor</a></li>
<li><a href="#_callable-constructors">5.2.5.3. Callable Constructors</a></li>
<li><a href="#_covariant-constructors">5.2.5.4. Covariant Constructors</a></li>
</ul>
</li>
<li><a href="#_data-fields">5.2.6. Data Fields</a>
<ul class="sectlevel4">
<li><a href="#data-fields-syntax">5.2.6.1. Syntax</a></li>
<li><a href="#data-fields-properties">5.2.6.2. Properties</a>
<ul class="sectlevel5">
<li><a href="#data-fields-semantics">5.2.6.2.1. Semantics</a></li>
<li><a href="#data-fields-type-inference">5.2.6.2.2. Type Inference</a></li>
</ul>
</li>
<li><a href="#_assignment-modifiers">5.2.6.3. Assignment Modifiers</a></li>
<li><a href="#_field-accessors-getter-setter">5.2.6.4. Field Accessors (Getter/Setter)</a>
<ul class="sectlevel5">
<li><a href="#field-acessors-syntax">5.2.6.4.1. Syntax</a></li>
<li><a href="#field-acessors-properties">5.2.6.4.2. Properties</a></li>
<li><a href="#field-accessors-semantics">5.2.6.4.3. Semantics</a></li>
</ul>
</li>
<li><a href="#optional-fields">5.2.6.5. Optional Fields</a>
<ul class="sectlevel5">
<li><a href="#_syntax-6">5.2.6.5.1. Syntax</a></li>
<li><a href="#_semantics-5">5.2.6.5.2. Semantics</a></li>
<li><a href="#_background">5.2.6.5.3. Background</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_static-members">5.2.7. Static Members</a>
<ul class="sectlevel4">
<li><a href="#_access-from-and-to-static-members">5.2.7.1. Access From and To Static Members</a></li>
<li><a href="#_generic-static-methods">5.2.7.2. Generic static methods</a></li>
<li><a href="#_static-members-of-interfaces">5.2.7.3. Static Members of Interfaces</a></li>
</ul>
</li>
<li><a href="#_redefinition-of-members">5.2.8. Redefinition of Members</a>
<ul class="sectlevel4">
<li><a href="#_overriding-of-members">5.2.8.1. Overriding of Members</a></li>
<li><a href="#_implementation-of-members">5.2.8.2. Implementation of Members</a>
<ul class="sectlevel5">
<li><a href="#_member-consumption">5.2.8.2.1. Member Consumption</a></li>
<li><a href="#_member-implementation">5.2.8.2.2. Member Implementation</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#_structural-typing">5.3. Structural Typing</a>
<ul class="sectlevel3">
<li><a href="#_syntax-7">5.3.1. Syntax</a></li>
<li><a href="#_definition-site-structural-typing">5.3.2. Definition Site Structural Typing</a></li>
<li><a href="#_use-site-structural-typing">5.3.3. Use-Site Structural Typing</a></li>
<li><a href="#structural-readWriteInit-field-typing">5.3.4. Structural Read-only, Write-only and Initializer Field Typing</a></li>
<li><a href="#_public-setter-annotated-with-code-providesinitializer-code">5.3.5. Public Setter Annotated With <code>ProvidesInitializer</code></a></li>
<li><a href="#_structural-types-with-optional-fields">5.3.6. Structural Types With Optional Fields</a></li>
<li><a href="#_structural-types-with-access-modifier">5.3.7. Structural Types With Access Modifier</a></li>
<li><a href="#_structural-types-with-additional-members">5.3.8. Structural Types With Additional Members</a>
<ul class="sectlevel4">
<li><a href="#_syntax-8">5.3.8.1. Syntax</a>
<ul class="sectlevel5">
<li><a href="#_semantics-6">5.3.8.1.1. Semantics</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_functions">6. Functions</a>
<ul class="sectlevel2">
<li><a href="functions.html#_function-type">6.1. Function Type</a>
<ul class="sectlevel3">
<li><a href="functions.html#_properties-5">6.1.1. Properties</a></li>
<li><a href="functions.html#function-type-inference">6.1.2. Type Inference</a></li>
<li><a href="functions.html#_autoboxing-of-function-type">6.1.3. Autoboxing of Function Type</a></li>
<li><a href="functions.html#_arguments-object">6.1.4. Arguments Object</a></li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-5-function-definition">6.2. ECMAScript 5 Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_function-declaration">6.2.1. Function Declaration</a>
<ul class="sectlevel4">
<li><a href="functions.html#_syntax-9">6.2.1.1. Syntax</a></li>
<li><a href="functions.html#_semantics-8">6.2.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="functions.html#_function-expression">6.2.2. Function Expression</a>
<ul class="sectlevel4">
<li><a href="functions.html#function-expression-syntax">6.2.2.1. Syntax</a></li>
<li><a href="functions.html#_semantics-and-type-inference">6.2.2.2. Semantics and Type Inference</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-2015-function-definition">6.3. ECMAScript 2015 Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_formal-parameters">6.3.1. Formal Parameters</a>
<ul class="sectlevel4">
<li><a href="functions.html#Type_Modifiers_Optional">6.3.1.1. Optional Parameters</a></li>
<li><a href="functions.html#Type_Modifiers_Default">6.3.1.2. Default Parameters</a></li>
<li><a href="functions.html#Type_Modifiers_Variadic">6.3.1.3. Variadic</a></li>
</ul>
</li>
<li><a href="functions.html#_generator-functions">6.3.2. Generator Functions</a>
<ul class="sectlevel4">
<li><a href="functions.html#generator-functions-syntax">6.3.2.1. Syntax</a></li>
<li><a href="functions.html#generator-functions-semantics">6.3.2.2. Semantics</a></li>
<li><a href="functions.html#_generator-arrow-functions">6.3.2.3. Generator Arrow Functions</a></li>
</ul>
</li>
<li><a href="functions.html#_arrow-function-expression">6.3.3. Arrow Function Expression</a>
<ul class="sectlevel4">
<li><a href="functions.html#arrow-function-expression-syntax">6.3.3.1. Syntax</a></li>
<li><a href="functions.html#arrow-function-expression-semantics-and-type-inference">6.3.3.2. Semantics and Type Inference</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-proposals-function-definition">6.4. ECMAScript Proposals Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_asynchronous-functions">6.4.1. Asynchronous Functions</a>
<ul class="sectlevel4">
<li><a href="functions.html#asynchronous-functions-syntax">6.4.1.1. Syntax</a></li>
<li><a href="functions.html#asynchronous-functions-semantics">6.4.1.2. Semantics</a></li>
<li><a href="functions.html#_asynchronous-arrow-functions">6.4.1.3. Asynchronous Arrow Functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_n4js-extended-function-definition">6.5. N4JS Extended Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_generic-functions">6.5.1. Generic Functions</a></li>
<li><a href="functions.html#_promisifiable-functions">6.5.2. Promisifiable Functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_conversions-and-reflection">7. Conversions and Reflection</a>
<ul class="sectlevel2">
<li><a href="conversions_and_reflection.html#_autoboxing-and-coercing">7.1. Autoboxing and Coercing</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_coercing">7.1.1. Coercing</a></li>
<li><a href="conversions_and_reflection.html#_autoboxing-of-primitives">7.1.2. Autoboxing of Primitives</a></li>
<li><a href="conversions_and_reflection.html#_autoboxing-of-function-expressions-and-declarations">7.1.3. Autoboxing of Function Expressions and Declarations</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_auto-conversion-of-objects">7.2. Auto-Conversion of Objects</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_auto-conversion-of-class-instances">7.2.1. Auto-Conversion of Class Instances</a>
<ul class="sectlevel4">
<li><a href="conversions_and_reflection.html#_auto-conversion-of-interface-instances">7.2.1.1. Auto-Conversion of Interface Instances</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_auto-conversion-of-enum-literals">7.2.2. Auto-Conversion of Enum Literals</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_type-cast-and-type-check">7.3. Type Cast and Type Check</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_type-cast">7.3.1. Type Cast</a></li>
<li><a href="conversions_and_reflection.html#_type-check">7.3.2. Type Check</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_reflection-meta-information">7.4. Reflection meta-information</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_reflection-for-classes">7.4.1. Reflection for Classes</a></li>
<li><a href="conversions_and_reflection.html#_reflection-for-interfaces">7.4.2. Reflection for Interfaces</a></li>
<li><a href="conversions_and_reflection.html#_reflection-for-enumerations">7.4.3. Reflection for Enumerations</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_conversion-of-primitive-types">7.5. Conversion of primitive types</a></li>
</ul>
</li>
<li><a href="expressions.html#_expressions">8. Expressions</a>
<ul class="sectlevel2">
<li><a href="expressions.html#_ecmascript-5-expressions">8.1. ECMAScript 5 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_the-this-literal">8.1.1. The this Literal</a></li>
<li><a href="expressions.html#_identifier">8.1.2. Identifier</a></li>
<li><a href="expressions.html#_literals">8.1.3. Literals</a>
<ul class="sectlevel4">
<li><a href="expressions.html#_integer-literals">8.1.3.1. Integer Literals</a></li>
</ul>
</li>
<li><a href="expressions.html#_array-literal">8.1.4. Array Literal</a></li>
<li><a href="expressions.html#_object-literal">8.1.5. Object Literal</a>
<ul class="sectlevel4">
<li><a href="expressions.html#_properties-6">8.1.5.1. Properties</a></li>
<li><a href="expressions.html#_scoping-and-linking">8.1.5.2. Scoping and linking</a></li>
</ul>
</li>
<li><a href="expressions.html#_parenthesized-expression-and-grouping-operator">8.1.6. Parenthesized Expression and Grouping Operator</a></li>
<li><a href="expressions.html#_property-accessors">8.1.7. Property Accessors</a>
<ul class="sectlevel4">
<li><a href="expressions.html#properties-1">8.1.7.1. Properties</a></li>
</ul>
</li>
<li><a href="expressions.html#_new-expression">8.1.8. New Expression</a></li>
<li><a href="expressions.html#_function-expression-2">8.1.9. Function Expression</a></li>
<li><a href="expressions.html#_function-calls">8.1.10. Function Calls</a></li>
<li><a href="expressions.html#_postfix-expression">8.1.11. Postfix Expression</a></li>
<li><a href="expressions.html#_unary-expression">8.1.12. Unary Expression</a></li>
<li><a href="expressions.html#_multiplicative-expression">8.1.13. Multiplicative Expression</a></li>
<li><a href="expressions.html#_additive-expression">8.1.14. Additive Expression</a>
<ul class="sectlevel4">
<li><a href="expressions.html#type-inference-10">8.1.14.1. Type Inference</a></li>
</ul>
</li>
<li><a href="expressions.html#_bitwise-shift-expression">8.1.15. Bitwise Shift Expression</a></li>
<li><a href="expressions.html#_relational-expression">8.1.16. Relational Expression</a></li>
<li><a href="expressions.html#_equality-expression">8.1.17. Equality Expression</a></li>
<li><a href="expressions.html#_binary-bitwise-expression">8.1.18. Binary Bitwise Expression</a></li>
<li><a href="expressions.html#_binary-logical-expression">8.1.19. Binary Logical Expression</a></li>
<li><a href="expressions.html#_conditional-expression">8.1.20. Conditional Expression</a></li>
<li><a href="expressions.html#_assignment-expression">8.1.21. Assignment Expression</a></li>
<li><a href="expressions.html#_comma-expression">8.1.22. Comma Expression</a></li>
</ul>
</li>
<li><a href="expressions.html#_ecmascript-6-expressions">8.2. ECMAScript 6 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_the-super-keyword">8.2.1. The super Keyword</a></li>
</ul>
</li>
<li><a href="expressions.html#_ecmascript-7-expressions">8.3. ECMAScript 7 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_await-expression">8.3.1. Await Expression</a></li>
</ul>
</li>
<li><a href="expressions.html#_n4js-specific-expressions">8.4. N4JS Specific Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_class-expression">8.4.1. Class Expression</a></li>
<li><a href="expressions.html#_cast-as-expression">8.4.2. Cast (As) Expression</a>
<ul class="sectlevel4">
<li><a href="expressions.html#cast-as-expression-semantics-type-inference">8.4.2.1. Semantics and Type Inference</a></li>
</ul>
</li>
<li><a href="expressions.html#Import_Calls">8.4.3. Import Calls</a></li>
</ul>
</li>
<li><a href="expressions.html#compile-time-expressions">8.5. Compile-Time Expressions</a></li>
</ul>
</li>
<li><a href="statements.html#_statements">9. Statements</a>
<ul class="sectlevel2">
<li><a href="statements.html#_ecmascript-5-statements">9.1. ECMAScript 5 Statements</a>
<ul class="sectlevel3">
<li><a href="statements.html#_function-or-field-accessor-bodies">9.1.1. Function or Field Accessor Bodies</a></li>
<li><a href="statements.html#_variable-statement">9.1.2. Variable Statement</a></li>
<li><a href="statements.html#_if-statement">9.1.3. If Statement</a></li>
<li><a href="statements.html#_iteration-statements">9.1.4. Iteration Statements</a></li>
<li><a href="statements.html#_return-statement">9.1.5. Return Statement</a></li>
<li><a href="statements.html#_with-statement">9.1.6. With Statement</a></li>
<li><a href="statements.html#_switch-statement">9.1.7. Switch Statement</a></li>
<li><a href="statements.html#_throw-try-and-catch-statements">9.1.8. Throw, Try, and Catch Statements</a></li>
<li><a href="statements.html#_debugger-statement">9.1.9. Debugger Statement</a></li>
</ul>
</li>
<li><a href="statements.html#_ecmascript-6-statements">9.2. ECMAScript 6 Statements</a>
<ul class="sectlevel3">
<li><a href="statements.html#_let">9.2.1. Let</a></li>
<li><a href="statements.html#_const">9.2.2. Const</a></li>
<li><a href="statements.html#_for-of-statement">9.2.3. <code>for &#8230;&#8203; of</code> statement</a></li>
<li><a href="statements.html#_import-statement">9.2.4. Import Statement</a>
<ul class="sectlevel4">
<li><a href="statements.html#Dynamic_Imports">9.2.4.1. Dynamic Imports</a></li>
<li><a href="statements.html#_immutabilaty-of-imports">9.2.4.2. Immutabilaty of Imports</a></li>
</ul>
</li>
<li><a href="statements.html#_export-statement">9.2.5. Export Statement</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="annotations.html#_annotations">10. Annotations</a>
<ul class="sectlevel2">
<li><a href="annotations.html#_introduction-2">10.1. Introduction</a>
<ul class="sectlevel3">
<li><a href="annotations.html#_syntax-13">10.1.1. Syntax</a></li>
<li><a href="annotations.html#_properties-7">10.1.2. Properties</a></li>
<li><a href="annotations.html#_element-specific-annotations">10.1.3. Element-Specific Annotations</a></li>
<li><a href="annotations.html#_general-annotations">10.1.4. General Annotations</a>
<ul class="sectlevel4">
<li><a href="annotations.html#_idebug">10.1.4.1. IDEBUG</a></li>
</ul>
</li>
<li><a href="annotations.html#idebug-syntax">10.1.5. Syntax</a>
<ul class="sectlevel4">
<li><a href="annotations.html#_semantics-11">10.1.5.1. Semantics</a></li>
<li><a href="annotations.html#_suppress-warnings">10.1.5.2. Suppress Warnings</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="annotations.html#_declaration-of-annotations">10.2. Declaration of Annotations</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_extended-fetaures">11. Extended Fetaures</a>
<ul class="sectlevel2">
<li><a href="extended_fetaures.html#_array-and-object-destructuring">11.1. Array and Object Destructuring</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_syntax-14">11.1.1. Syntax</a></li>
<li><a href="extended_fetaures.html#_semantics-12">11.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_dependency-injection">11.2. Dependency Injection</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_di-components-and-injectors">11.2.1. DI Components and Injectors</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_dicomponent-relations">11.2.1.1. DIComponent Relations</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_binders-and-bindings">11.2.2. Binders and Bindings</a></li>
<li><a href="extended_fetaures.html#_injection-points">11.2.3. Injection Points</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_field-injection">11.2.3.1. Field Injection</a></li>
<li><a href="extended_fetaures.html#_constructor-injection">11.2.3.2. Constructor Injection</a></li>
<li><a href="extended_fetaures.html#_method-injection">11.2.3.3. Method Injection</a>
<ul class="sectlevel5">
<li><a href="extended_fetaures.html#_provider">11.2.3.3.1. Provider</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="extended_fetaures.html#_n4js-di-life-cycle-and-scopes">11.2.4. N4JS DI Life Cycle and Scopes</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_injection-cylces">11.2.4.1. Injection Cylces</a></li>
<li><a href="extended_fetaures.html#_default-scope">11.2.4.2. Default Scope</a></li>
<li><a href="extended_fetaures.html#_singleton-scope">11.2.4.3. Singleton Scope</a></li>
<li><a href="extended_fetaures.html#_per-injection-chain-singleton">11.2.4.4. Per Injection Chain Singleton</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_validation-of-callsites-targeting-n4injector-methods">11.2.5. Validation of callsites targeting N4Injector methods</a></li>
<li><a href="extended_fetaures.html#_n4js-di-annotations">11.2.6. N4JS DI Annotations</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_n4js-di-generateinjector">11.2.6.1. N4JS DI @GenerateInjector</a></li>
<li><a href="extended_fetaures.html#_n4js-di-withparentinjector">11.2.6.2. N4JS DI @WithParentInjector</a></li>
<li><a href="extended_fetaures.html#_n4js-di-usebinder">11.2.6.3. N4JS DI @UseBinder</a></li>
<li><a href="extended_fetaures.html#_n4js-di-binder">11.2.6.4. N4JS DI @Binder</a></li>
<li><a href="extended_fetaures.html#_n4js-di-bind">11.2.6.5. N4JS DI @Bind</a></li>
<li><a href="extended_fetaures.html#_n4js-di-provides">11.2.6.6. N4JS DI @Provides</a></li>
<li><a href="extended_fetaures.html#_n4js-di-inject">11.2.6.7. N4JS DI @Inject</a></li>
<li><a href="extended_fetaures.html#_n4js-di-singleton">11.2.6.8. N4JS DI @Singleton</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="extended_fetaures.html#_test-support">11.3. Test Support</a></li>
<li><a href="extended_fetaures.html#_polyfill-definitions">11.4. Polyfill Definitions</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_runtime-polyfill-definitions">11.4.1. Runtime Polyfill Definitions</a></li>
<li><a href="extended_fetaures.html#_static-polyfill-definitions">11.4.2. Static Polyfill Definitions</a></li>
<li><a href="extended_fetaures.html#_transpiling-static-polyfilled-classes">11.4.3. Transpiling static polyfilled classes</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="components.html#_components">12. Components</a>
<ul class="sectlevel2">
<li><a href="components.html#_overview-2">12.1. Overview</a></li>
<li><a href="components.html#Component_Types">12.2. Component Types</a>
<ul class="sectlevel3">
<li><a href="components.html#_libraries">12.2.1. Libraries</a></li>
<li><a href="components.html#_runtime-environment-and-runtime-libraries">12.2.2. Runtime Environment and Runtime Libraries</a></li>
<li><a href="components.html#_tests">12.2.3. Tests</a></li>
<li><a href="components.html#_type-definitions">12.2.4. Type Definitions</a></li>
</ul>
</li>
<li><a href="components.html#package-json">12.3. Package.json File</a>
<ul class="sectlevel3">
<li><a href="components.html#_basic-properties">12.3.1. Basic Properties</a></li>
<li><a href="components.html#_n4js-properties">12.3.2. N4JS Properties</a></li>
<li><a href="components.html#_constraints">12.3.3. Constraints</a></li>
</ul>
</li>
<li><a href="components.html#_support-for-npm-scopes">12.4. Support for NPM Scopes</a></li>
<li><a href="components.html#sec:N4JS-Type-Definitions">12.5. N4JS Type Definitions</a>
<ul class="sectlevel3">
<li><a href="components.html#_specify-type-definition">12.5.1. Specify Type Definition</a></li>
<li><a href="components.html#_name-conventions">12.5.2. Name Conventions</a></li>
<li><a href="components.html#_version-conventions">12.5.3. Version Conventions</a>
<ul class="sectlevel4">
<li><a href="components.html#_define-a-new-type-definition-package">12.5.3.1. Define a New Type Definition Package</a></li>
<li><a href="components.html#_using-a-type-definition-package">12.5.3.2. Using a Type Definition Package</a></li>
<li><a href="components.html#_rational">12.5.3.3. Rational</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="components.html#_modules">12.6. Modules</a></li>
<li><a href="components.html#_api-and-implementation-component">12.7. API and Implementation Component</a>
<ul class="sectlevel3">
<li><a href="components.html#_execution-of-api-and-implementation-components">12.7.1. Execution of API and Implementation Components</a></li>
<li><a href="components.html#_api-and-implementation-with-di">12.7.2. API and Implementation With DI</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="plainjs.html#_plainjs">13. PlainJS</a>
<ul class="sectlevel2">
<li><a href="plainjs.html#_type-inference-and-validation-for-plain-js">13.1. Type Inference and Validation for Plain JS</a></li>
<li><a href="plainjs.html#_external-declarations">13.2. External Declarations</a>
<ul class="sectlevel3">
<li><a href="plainjs.html#_declaring-externals">13.2.1. Declaring externals</a></li>
<li><a href="plainjs.html#_instantiating-external-classes">13.2.2. Instantiating external classes</a></li>
<li><a href="plainjs.html#_implementation-of-external-declarations">13.2.3. Implementation of External Declarations</a></li>
<li><a href="plainjs.html#_example">13.2.4. Example</a></li>
</ul>
</li>
<li><a href="plainjs.html#_global-definitions">13.3. Global Definitions</a></li>
<li><a href="plainjs.html#_runtime-definitions">13.4. Runtime Definitions</a></li>
<li><a href="plainjs.html#_applying-polyfills">13.5. Applying Polyfills</a></li>
</ul>
</li>
<li><a href="jsdoc.html#_jsdoc-2">14. JSDoc</a>
<ul class="sectlevel2">
<li><a href="jsdoc.html#_general-n4jsdoc-features">14.1. General N4JSDoc Features</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#_provided-inline-tags">14.1.1. Provided Inline Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag__code">14.1.1.1. @code</a></li>
<li><a href="jsdoc.html#jsdoc_tag__link">14.1.1.2. @link</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="jsdoc.html#_n4jsdoc-for-user-projects">14.2. N4JSdoc for User Projects</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#_standard-tags">14.2.1. Standard Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#_-author">14.2.1.1. @author</a></li>
<li><a href="jsdoc.html#jsdoc_tag_param">14.2.1.2. @param</a></li>
<li><a href="jsdoc.html#jsdoc_tag_return">14.2.1.3. @return</a></li>
</ul>
</li>
<li><a href="jsdoc.html#_test-related-tags">14.2.2. Test Related Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag__testee">14.2.2.1. @testee</a></li>
<li><a href="jsdoc.html#jsdoc_tag__testeeFromType">14.2.2.2. @testeeFromType</a></li>
<li><a href="jsdoc.html#_testeeType_and__testeeMember">14.2.2.3. @testeeType and @testeeMember</a></li>
<li><a href="jsdoc.html#jsdoc_tag_reqid_in_Tests">14.2.2.4. @reqid in Tests</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="jsdoc.html#_n4jsdoc-for-api-and-implementation-projects">14.3. N4JSDoc for API and Implementation Projects</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#jsdoc_tag__apiNote">14.3.1. @apiNote</a></li>
<li><a href="jsdoc.html#API_Project_Tags">14.3.2. API Project Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag_apiState">14.3.2.1. @apiState</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="jsx.html#_jsx">15. JSX</a>
<ul class="sectlevel2">
<li><a href="jsx.html#_jsx-support">15.1. JSX Support</a></li>
<li><a href="jsx.html#_jsx-backend">15.2. JSX Backend</a></li>
</ul>
</li>
<li><a href="grammars.html#_grammars">16. Grammars</a>
<ul class="sectlevel2">
<li><a href="grammars.html#_type-expressions-grammar">16.1. Type Expressions Grammar</a></li>
<li><a href="grammars.html#_n4js-language-grammar">16.2. N4JS Language Grammar</a></li>
</ul>
</li>
<li><a href="jsobjects.html#_jsobjects">17. JSObjects</a>
<ul class="sectlevel2">
<li><a href="jsobjects.html#_object">17.1. Object</a></li>
<li><a href="jsobjects.html#_string">17.2. String</a></li>
<li><a href="jsobjects.html#_boolean">17.3. Boolean</a></li>
<li><a href="jsobjects.html#_number">17.4. Number</a>
<ul class="sectlevel3">
<li><a href="jsobjects.html#_static-attributes">17.4.1. Static Attributes</a></li>
</ul>
</li>
<li><a href="jsobjects.html#function">17.5. Function</a></li>
<li><a href="jsobjects.html#_error">17.6. Error</a></li>
<li><a href="jsobjects.html#_array">17.7. Array</a></li>
<li><a href="jsobjects.html#_date">17.8. Date</a></li>
<li><a href="jsobjects.html#_math">17.9. Math</a>
<ul class="sectlevel3">
<li><a href="jsobjects.html#static-attributes-1">17.9.1. Static Attributes</a></li>
</ul>
</li>
<li><a href="jsobjects.html#_regexp">17.10. RegExp</a></li>
<li><a href="jsobjects.html#_json">17.11. JSON</a></li>
</ul>
</li>
<li><a href="n4js_objects.html#_n4js-objects">18. N4JS Objects</a>
<ul class="sectlevel2">
<li><a href="n4js_objects.html#_reflection-model">18.1. Reflection Model</a></li>
<li><a href="n4js_objects.html#_error-types">18.2. Error Types</a>
<ul class="sectlevel3">
<li><a href="n4js_objects.html#_n4apinotimplemented">18.2.1. N4ApiNotImplemented</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="appendix_a_acronyms.html#_acronyms">Appendix A: Acronyms</a></li>
<li><a href="appendix_b_license.html#sec:License">Appendix B: License</a></li>
<li><a href="appendix_c_bibliography.html#_bibliography">Appendix C: Bibliography</a></li>
</ul>
</div>
</div>
<div id="content"><div class="sect1">
<h2 id="_classifiers"><a class="anchor" href="#_classifiers"></a><a class="link" href="#_classifiers">5. Classifiers</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_n4js-specific-classifiers"><a class="anchor" href="#_n4js-specific-classifiers"></a><a class="link" href="#_n4js-specific-classifiers">5.1. N4JS Specific Classifiers</a></h3>
<div class="paragraph">
<p>N4JS provides three new metatypes: class, interface, and enums.
In this section we describe classes and interfaces.
These metatypes, called <em>classifiers</em>, share some common properties which are described before type specific properties are outlined in the following sections.</p>
</div>
<div class="paragraph">
<p>All of these metatypes can be marked with type access modifiers:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">enum N4JSTypeAccessModifier: project | public;</code></pre>
</div>
</div>
<div class="sect3 language-n4js">
<h4 id="_properties-2"><a class="anchor" href="#_properties-2"></a><a class="link" href="#_properties-2">5.1.1. Properties</a></h4>
<div class="paragraph">
<p><strong>Properties defined by syntactic elements:</strong></p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>annotations</code> </dt>
<dd>
<p>Arbitrary annotations, see <a href="annotations.html#_annotations">Annotations</a> for details.</p>
</dd>
<dt class="hdlist1"><code>accessModifier</code> </dt>
<dd>
<p>N4JS type access modifier: <code>public</code>, or <code>project</code>; <code>public</code> can be combined with <code>@Internal</code>; if
<strong>export</strong> is <code>true</code> the default is else the default is <code>private</code>.</p>
</dd>
<dt class="hdlist1"><code>name</code> </dt>
<dd>
<p>The simple name of a classifier. If the classifier is defined by an anonymous class expression, an artificial but unique name is created.
The name needs to be a valid identifier, see <a href="names.html#_valid-names">Valid Names</a>.</p>
</dd>
<dt class="hdlist1"><code>typePars</code> </dt>
<dd>
<p>Collection of type parameters of a generic classifier; empty by default.</p>
</dd>
<dt class="hdlist1"><code>ownedMembers</code> </dt>
<dd>
<p>Collection of owned members, i.e. methods and fields defined directly in the classifier and, if present, the explicitly defined constructor.
Depending on the concrete classifier, additional constraints are defined.</p>
</dd>
<dt class="hdlist1"><code>typingStrategy</code> </dt>
<dd>
<p>The definition-site typing strategy. By default nominal typing is used.
See <a href="#_structural-typing">Structural Typing</a> for details.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p><strong>The following pseudo properties are defined via annotations:</strong></p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>export</code> </dt>
<dd>
<p>Boolean property set to true if the <code>export</code> modifier is set.
If value is true, the classifier may be accessible outside the project.</p>
</dd>
<dt class="hdlist1"><code>final</code> </dt>
<dd>
<p>Boolean property which is set to final if annotation <code>@Final</code> is set.
Also see <a href="#_final-modifier">Final Modifier</a></p>
</dd>
<dt class="hdlist1"><code>deprecated</code> </dt>
<dd>
<p>Boolean property set to true if annotation <code>@Deprecated</code> is set.</p>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Version 0.4, not implemented in Version 0.3
</td>
</tr>
</table>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p><strong>We additionally define the following pseudo properties:</strong></p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>acc</code> </dt>
<dd>
<p>Type access modifier as described in <a href="names.html#_accessibility-of-types-top-level-variables-and-function-declarations">Accessibility of Types, Top-Level Variables and Function Declarations</a>, it is the aggregated value of the
<code>accessModifier</code> and the <strong>export</strong> property.</p>
</dd>
<dt class="hdlist1"><code>owned{Fields|Methods|Getters|Setters|Accessors}</code> </dt>
<dd>
<p>Filters ownedMembers by metatype, short for<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>x</mi><mo></mo><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>d</mi><mi>M</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi><mo>,</mo><mi>μ</mi><mfenced close=")" open="("><mi>x</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>Field</mtext></mstyle></math> etc.</p>
</dd>
<dt class="hdlist1"><code>members</code> </dt>
<dd>
<p>Reflexive transitive closure of all members of a classifier and its super classifiers, see <a href="#_common-semantics-of-classifiers">Common Semantics of Classifiers</a> on how this is calculated.</p>
</dd>
<dt class="hdlist1"><code>fields|methods|getters|setters|accessors</code> </dt>
<dd>
<p>Filters members by metatype, short for<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>x</mi><mo></mo><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi><mo>,</mo><mi>μ</mi><mfenced close=")" open="("><mi>x</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>Field</mtext></mstyle></math> etc.</p>
</dd>
<dt class="hdlist1"><code>superClassifiers</code> </dt>
<dd>
<p>Classes and interface may extend or implement classes or interfaces.
Any class or interface extended or interface implemented is called <em>super classifier</em>.
We distinguish the directly subtyped classifiers and from the transitive closure of supertypes <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>f</mi><mi>i</mi><mi>e</mi><mi>r</mi><msup><mi>s</mi><mo>*</mo></msup></math></p>
</dd>
</dl>
</div>
</div>
<div class="sect3 language-n4js">
<h4 id="_common-semantics-of-classifiers"><a class="anchor" href="#_common-semantics-of-classifiers"></a><a class="link" href="#_common-semantics-of-classifiers">5.1.2. Common Semantics of Classifiers</a></h4>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-42"></a><strong>Req. IDE-42:</strong> <a href="#Req-IDE-42">Subtyping of Classifiers</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given type <code>C</code>, and supertypes <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>f</mi><mi>i</mi><mi>e</mi><mi>r</mi><mi>s</mi><mo>=</mo><mfenced close="}" open="{"><msub><mi>S</mi><mn>1</mn></msub><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><msub><mi>S</mi><mi>n</mi></msub></mfenced></math> directly subtyped
<code>C</code>, the following constraints must be true:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The supertypes must be accessible to the subtype:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mi>n</mi></msub></math> must be accessible to <code>C</code>.</p>
</li>
<li>
<p>All type parameters of the direct supertypes have to be bound by type arguments in the subtype and the type arguments have to be substitutable types of the type parameters.</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mn>0</mn><mo>&lt;</mo><mi>i</mi><mo></mo><mi>k</mi><mi>:</mi><mo></mo><mi>P</mi><mo></mo><msub><mi>S</mi><mi>i</mi></msub><mi>:</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>A</mi><mo></mo><msub><mi>C</mi><mo>.</mo></msub><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><mi>g</mi><mi>s</mi><mi>:</mi><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi><mfenced close=")" open="("><mi>A</mi><mi>P</mi></mfenced><mo></mo><mi>A</mi><mo>.</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mo>&lt;</mo><mi>:</mi><mi>P</mi><mo>.</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi></math></p>
</div>
</li>
<li>
<p>Wildcards may not be used as type argument when binding a supertype’s type parameters.</p>
</li>
<li>
<p>A classifier cannot be directly subtyped directly multiple times:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><msub><mi>S</mi><mi>i</mi></msub><mo>,</mo><msub><mi>S</mi><mi>j</mi></msub><mfenced close=")" open="("><mi>i</mi><mrow><mi>j</mi><mo></mo><mfenced close="}" open="{"><mrow><mn>1.</mn><mo>.</mo><mi>n</mi></mrow></mfenced></mrow></mfenced><mi>:</mi><msub><mi>S</mi><mi>i</mi></msub><mo>=</mo><msub><mi>S</mi><mi>j</mi></msub><mo></mo><mi>i</mi><mo>=</mo><mi>j</mi></math></p>
</li>
</ol>
</div>
<div class="paragraph">
<p>In order to simplify the following constraints, we use the pseudo property <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi></math> to refer to all members of a classifier.
This includes all members directly declared by the classifier itself, i.e. the <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>d</mi><mi>M</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi></math>, and all members inherited from its super classifiers.
The concrete mechanisms for inheriting a member are different and further constraint (cf. <a href="#_redefinition-of-members">Redefinition of Members</a>).
A classifier only inherits its members from its direct supertypes, although the supertypes may contains members inherited from their supertypes.</p>
</div>
</div>
</div>
</div>
<div class="sect3 language-n4js">
<h4 id="_classes"><a class="anchor" href="#_classes"></a><a class="link" href="#_classes">5.1.3. Classes</a></h4>
<div class="sect4">
<h5 id="_definition-of-classes"><a class="anchor" href="#_definition-of-classes"></a><a class="link" href="#_definition-of-classes">5.1.3.1. Definition of Classes</a></h5>
<div class="paragraph">
<p>Classes are either declared with a class declaration on top level, or they can be used as anonymous classes in expressions.
The latter may have a name, which may be used for error messages and reflection.</p>
</div>
<div class="paragraph">
<p>At the current stage, class expressions are effectively disabled at least until the semantics of them are finalized in ECMAScript 6.</p>
</div>
<div class="paragraph">
<p>In N4JS (as in many other languages) multi-inheritance of classes is not supported.
Although the <code>diamond problem</code> (of functions being defined in both superclasses) could be solved via union and intersection types, this would lead to problems when calling these super implementations.
This is particularly an issue due to JavaScript not supporting
multiple prototypes.<sup class="footnote">[<a id="_footnoteref_27" class="footnote" href="appendix_c_bibliography.html#_footnote_27" title="View footnote.">27</a>]</sup>
Interfaces, however, allow for multi-inheritance. Since the former can also define functions with bodies, this is not a hard restriction.</p>
</div>
<div class="sect5">
<h6 id="class-syntax"><a class="anchor" href="#class-syntax"></a><a class="link" href="#class-syntax">5.1.3.1.1. Syntax</a></h6>
<div class="listingblock">
<div class="title">Syntax N4 Class Declaration and Expression</div>
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">N4ClassDeclaration &lt;Yield&gt;:
=&gt;(
{N4ClassDeclaration}
annotations+=Annotation*
(declaredModifiers+=N4Modifier)*
'class' typingStrategy=TypingStrategyDefSiteOperator? name=BindingIdentifier&lt;Yield&gt;?
)
TypeVariables?
ClassExtendsClause&lt;Yield&gt;?
Members&lt;Yield&gt;
;
N4ClassExpression &lt;Yield&gt;:
{N4ClassExpression}
'class' name=BindingIdentifier&lt;Yield&gt;?
ClassExtendsClause&lt;Yield&gt;?
Members&lt;Yield&gt;;
fragment ClassExtendsClause &lt;Yield&gt;*:
'extends' (
=&gt;superClassRef=ParameterizedTypeRefNominal ('implements' ClassImplementsList)?
| superClassExpression=LeftHandSideExpression&lt;Yield&gt;
)
| 'implements' ClassImplementsList
;
fragment ClassImplementsList*:
implementedInterfaceRefs+=ParameterizedTypeRefNominal
(',' implementedInterfaceRefs+=ParameterizedTypeRefNominal)*
;
fragment Members &lt;Yield&gt;*:
'{'
ownedMembers+=N4MemberDeclaration&lt;Yield&gt;*
'}'
;</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="class-properties"><a class="anchor" href="#class-properties"></a><a class="link" href="#class-properties">5.1.3.1.2. Properties</a></h6>
<div class="paragraph">
<p>These are the properties of class, which can be specified by the user:
Syntax N4 Class Declaration and Expression</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>abstract</code> </dt>
<dd>
<p>Boolean flag indicating whether class may be instantiable; default is <code>false</code>, see <a href="#_abstract-classes">Abstract Classes</a>.</p>
</dd>
<dt class="hdlist1"><code>external</code> </dt>
<dd>
<p>Boolean flag indicating whether class is a declaration without implementation or with an external (non-N4JS) implementation; default is <code>false</code>, see <a href="#_definition-site-structural-typing">Definition Site Structural Typing</a>.</p>
</dd>
<dt class="hdlist1"><code>defStructural</code> </dt>
<dd>
<p>Boolean flag indicating whether subtype relation uses nominal or structural typing, see <a href="#_definition-site-structural-typing">Definition Site Structural Typing</a> for details.</p>
</dd>
<dt class="hdlist1"><code>superType/sup</code> </dt>
<dd>
<p>The type referenced by <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> is called direct superclass of a class, and vice versa the class is a direct subclass of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></math>.
Instead of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></math>, we sometimes simply write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><mi>p</mi></math>.
The derived set <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><msup><mi>p</mi><mo>+</mo></msup></math> is defined as the transitive closures of all direct and indirect superclasses of a class.
If no supertype is explicitly stated, classes are derived from <code>N4Object</code>.</p>
</dd>
<dt class="hdlist1"><code>implementedInterfaces</code>/<code>interfaces</code> </dt>
<dd>
<p>Collection of interfaces directly <em>implemented</em> by the class; empty by default.
Instead of <code>implementedInterfaces</code>, we simply write <code>interfaces</code>.</p>
</dd>
<dt class="hdlist1"><code>ownedCtor</code> </dt>
<dd>
<p>Explicit constructor of a class (if any), see <a href="types.html#_constructor-and-classifier-type">Constructor and Classifier Type</a>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>And we additionally define the following pseudo properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>ctor</code> </dt>
<dd>
<p>Explicit or implicit constructor of a class, see <a href="types.html#_constructor-and-classifier-type">Constructor and Classifier Type</a>.</p>
</dd>
<dt class="hdlist1"><code>fields</code> </dt>
<dd>
<p>Further derived properties for retrieving all methods (property <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi></math>), fields (property <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi><mi>s</mi></math>), static
members (property <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>t</mi><mi>a</mi><mi>t</mi><mi>i</mi><mi>c</mi><mi>O</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>d</mi><mi>M</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi></math>), etc. can easily be added by filtering properties <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi></math> or <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>d</mi><mi>M</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi></math>.</p>
</dd>
</dl>
</div>
</div>
<div class="sect5">
<h6 id="class-type-inference"><a class="anchor" href="#class-type-inference"></a><a class="link" href="#class-type-inference">5.1.3.1.3. Type Inference</a></h6>
<div class="paragraph">
<p>The type of a class declaration or class expression <code>C</code> (i.e., a class definition in general) is of type <code>constructor{C}</code> if it is not abstract,
that is if it can be instantiated.
If it is abstract, the type of the definition simply is <code>type{C}</code>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mfrac><mrow><mo>¬</mo><mi>C</mi><mo>.</mo><mi>a</mi><mi>b</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>c</mi><mi>t</mi></mrow><mrow><mi>Γ</mi><mo></mo><mi>C</mi><mi>:</mi><mstyle mathvariant="monospace"><mtext>constructor</mtext></mstyle><mfenced close="}" open="{"><mi>C</mi></mfenced></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow><mi>C</mi><mo>.</mo><mi>a</mi><mi>b</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>c</mi><mi>t</mi></mrow><mrow><mi>Γ</mi><mo></mo><mi>C</mi><mi>:</mi><mstyle mathvariant="monospace"><mtext>type</mtext></mstyle><mfenced close="}" open="{"><mi>C</mi></mfenced></mrow></mfrac></mtd></mtr></mtable></math>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-43"></a><strong>Req. IDE-43:</strong> <a href="#Req-IDE-43">Structural and Nominal Supertypes</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>The type of supertypes and implemented interfaces is always the nominal type, even if the supertype is declared structurally.</p>
</div>
<div class="openblock">
<div class="content">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect4">
<h5 id="class-semantics"><a class="anchor" href="#class-semantics"></a><a class="link" href="#class-semantics">5.1.3.2. Semantics</a></h5>
<div class="paragraph">
<p>This section deals with the (more or less) type-independent constraints on classes.</p>
</div>
<div class="paragraph">
<p>Class expressions are not fully supported at the moment.</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="transitive_closure_of_members"></a><strong>Definition:</strong> <a href="#transitive_closure_of_members">Transitive closure of members</a></p>
</div>
<div class="paragraph">
<p>The reflexive transitive closure of members of a class is indirectly defined by the override and implementation constraints defined in <a href="#_redefinition-of-members">Redefinition of Members</a>.</p>
</div>
<div class="paragraph">
<p>Note that since overloading is forbidden, the following constraint is true <sup class="footnote">[<a id="_footnoteref_28" class="footnote" href="appendix_c_bibliography.html#_footnote_28" title="View footnote.">28</a>]</sup>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo></mo><msub><mi>m</mi><mn>1</mn></msub><mo>,</mo><msub><mi>m</mi><mn>2</mn></msub><mo></mo><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>:</mi><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo></mo><msub><mi>m</mi><mn>1</mn></msub><mo>=</mo><msub><mi>m</mi><mn>2</mn></msub><mo></mo><mi>a</mi><mi>c</mi><mi>c</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi>o</mi><mi>r</mi><mi>P</mi><mi>a</mi><mi>i</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>m</mi><mn>1</mn></msub><msub><mi>m</mi><mn>2</mn></msub></mfenced></math>
</div>
</div>
<div class="paragraph">
<p>Remarks: Class and method definition is quite similar to the proposed ECMAScript version 6 draft [<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.S13.5)</a>], except that an N4 class and members may contain</p>
</div>
<div class="ulist">
<ul>
<li>
<p>annotations, abstract and access modifiers</p>
</li>
<li>
<p>fields</p>
</li>
<li>
<p>types</p>
</li>
<li>
<p>implemented interfaces</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Note that even <code>static</code> is used in ECMAScript 6.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>Mixing in members (i.e. interface’s methods with default implementation or fields) is similar to mixing in members from roles as defined in [<a href="appendix_c_bibliography.html#Dart13a">Dart13a(p.S9.1)</a>].
It is also similar to default implementations in Java 8 [<a href="appendix_c_bibliography.html#Gosling15a">Gosling15a</a>].
In Java, however, more constraints exist, (for example, methods of interfaces must be public).</p>
</div>
<div class="exampleblock">
<div class="title">Example 30. Simple Class</div>
<div class="content">
<div class="paragraph">
<p>This first example shows a very simple class with a field, a constructor and a method.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class C {
data: any;
constructor(data: any) {
this.data = data;
}
foo(): void { }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 31. Extend and implement</div>
<div class="content">
<div class="paragraph">
<p>The following example demonstrate how a class can extend a superclass and implement an interface.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">interface I {
foo(): void
}
class C{}
class X extends C implements I {
@Override
foo(): void {}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>A class <code>C</code> is a subtype of another classifier <code>S</code> (which can be a class or interface) if the other classifier <code>S</code> is (transitively) contained in the supertypes (superclasses or implemented interfaces) of the class:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>l</mi><mi>e</mi><mi>f</mi><mi>t</mi><mo>=</mo><mi>r</mi><mi>i</mi><mi>g</mi><mi>h</mi><mi>t</mi></mrow><mrow><mi>Γ</mi><mo></mo><mstyle mathvariant="monospace"><mtext>TClass</mtext></mstyle><mi> </mi><mi>l</mi><mi>e</mi><mi>f</mi><mi>t</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mfenced close="]" open="["><mrow><mi>T</mi><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi></mrow></mfenced><mi> </mi><mi>r</mi><mi>i</mi><mi>g</mi><mi>h</mi><mi>t</mi></mrow></mfrac><mfenced close="]" open="["><mrow><mi>s</mi><mi>h</mi><mi>o</mi><mi>r</mi><mi>t</mi><mi>c</mi><mi>u</mi><mi>t</mi></mrow></mfenced><mtext>
</mtext></math>
</div>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>Γ</mi><mo></mo><mi>l</mi><mi>e</mi><mi>f</mi><mi>t</mi><mo>.</mo><mi>s</mi><mi>u</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>.</mo><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>r</mi><mi>i</mi><mi>g</mi><mi>h</mi><mi>t</mi></mrow><mrow><mi>Γ</mi><mo></mo><mstyle mathvariant="monospace"><mtext>TClass</mtext></mstyle><mi> </mi><mi>l</mi><mi>e</mi><mi>f</mi><mi>t</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mfenced close="]" open="["><mrow><mi>T</mi><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi></mrow></mfenced><mi> </mi><mi>r</mi><mi>i</mi><mi>g</mi><mi>h</mi><mi>t</mi></mrow></mfrac></math>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-44"></a><strong>Req. IDE-44:</strong> <a href="#Req-IDE-44">Implicit Supertype of Classes</a> (ver. 1)</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The implicit supertype of all classes is <code>N4Object</code>.
All classes with no explicit supertype are inherited from <code>N4Object</code>.</p>
</li>
<li>
<p>If the supertype is explicitly set to <code>Object</code>, then the class is not derived from <code>N4Object</code>.
Meta-information is created similar to an <code>N4Object</code>-derived class.
Usually, there is no reason to explicitly derive a class from <code>Object</code>.</p>
</li>
<li>
<p>External classes are implicitly derived from , unless they are annotated with <code>@N4JS</code>(cf.<a href="plainjs.html#_external-declarations">External Declarations</a>).</p>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_final-modifier"><a class="anchor" href="#_final-modifier"></a><a class="link" href="#_final-modifier">5.1.3.3. Final Modifier</a></h5>
<div class="paragraph">
<p>Extensibility refers to whether a given classifier can be subtyped.
Accessibility is a prerequisite for extensibility.
If a type cannot be seen, it cannot be subclassed.
The only modifier influencing the extensibility directly is the annotation <code>@Final</code>, which prevents all subtyping.
The following table shows how to prevent other projects or vendors from subtyping by also restricting the accessibility of the constructor:</p>
</div>
<table class="tableblock frame-all grid-all spread">
<caption class="title">Table 6. Extensibility of Types</caption>
<colgroup>
<col style="width: 62.5%;">
<col style="width: 12.5%;">
<col style="width: 12.5%;">
<col style="width: 12.5%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-center valign-top">Type <code>C</code> Settings</th>
<th class="tableblock halign-center valign-top" colspan="3">Subclassed in</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><strong>Project</strong></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><strong>Vendor</strong></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><strong>World</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>C.final</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>C.ctor.accessModifier=\lenum{project}</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>C.ctor.accessModifier=\lenum{public@Internal}</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>Since interfaces are always to be implemented, they must not be declared final.</p>
</div>
</div>
<div class="sect4">
<h5 id="_abstract-classes"><a class="anchor" href="#_abstract-classes"></a><a class="link" href="#_abstract-classes">5.1.3.4. Abstract Classes</a></h5>
<div class="paragraph">
<p>A class with modifier <code>abstract</code> is called an <em>abstract class</em> and has its <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>a</mi><mi>b</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>c</mi><mi>t</mi></math> property set to true.
Other classes are called <em>concrete</em> classes.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-45"></a><strong>Req. IDE-45:</strong> <a href="#Req-IDE-45">Abstract Class</a> (ver. 1)</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>A class <code>C</code> must be declared abstract if it owns or inherits one or more abstract members and neither C nor any interfaces implemented by C implements these members.
A concrete class has to, therefore, implement all abstract members of its superclasses’ implemented interfaces.
Note that a class may implement fields with field accessors and vice versa.</p>
</li>
<li>
<p>An abstract class may not be instantiated.</p>
</li>
<li>
<p>An abstract class cannot be set to final (with annotation <code>@Final</code>).</p>
</li>
</ol>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-46"></a><strong>Req. IDE-46:</strong> <a href="#Req-IDE-46">Abstract Member</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p></p>
</div>
<div class="sidebarblock">
<div class="content">
<a href="https://github.com/eclipse/n4js/issues/1047" class="gray" title="GitHub Issues"><span class="image"><img src="images/issue.svg" alt=""></span> #1047</a>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>A member declared as abstract must not have a method body (in contrary a method not declared as abstract have to have a method body).</p>
</li>
<li>
<p>Only methods, getters and setters can be declared as abstract (fields cannot be abstract).</p>
</li>
<li>
<p>It is not possible to inherit from an abstract class which contains abstract members which are not visible in the subclass.</p>
</li>
<li>
<p>An abstract member must not be set to final (with annotation <code>@Final</code>).</p>
</li>
<li>
<p>Static members must not be declared abstract.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="paragraph">
<p>Remarks:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>We decided to disallow abstract static members, since we cannot guarantee that a static members is not accessed in all cases</p>
</li>
<li>
<p>Only static members can override static members and only instance members can override other instance members of course.</p>
</li>
<li>
<p>An abstract member must not be declared in a final class (i.e. a class annotated with <code>@Final</code>). This is not explicitly defined as constraint in <a href="#Req-IDE-46">[Req-IDE-46]</a> since abstract classes must not defined final anyway. We also do not produce error message for abstract members in final classes since these errors would be consequential errors.</p>
</li>
</ul>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title=""></i>
</td>
<td class="content">
Abstract members might be declared private, as they can be accessed from within the module.
This is to be changed in order to be aligned with TypeScript, cf. <a href="https://github.com/eclipse/n4js/issues/1221" class="gray" title="GitHub Issues"><span class="image"><img src="images/issue.svg" alt=""></span> #1221</a>. However we also want to add class expressions&#8201;&#8212;&#8201;and then the abstract members may be accessed (and overridden) in nested classes created by means of class expressions.
</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="_non-instantiable-classes"><a class="anchor" href="#_non-instantiable-classes"></a><a class="link" href="#_non-instantiable-classes">5.1.3.5. Non-Instantiable Classes</a></h5>
<div class="paragraph">
<p>To make a class non-instantiable outside a defining compilation unit, i.e. disallow creation of instances for this class, simply declare the constructor as private.
This can be used for singletons.</p>
</div>
</div>
<div class="sect4">
<h5 id="_superclass"><a class="anchor" href="#_superclass"></a><a class="link" href="#_superclass">5.1.3.6. Superclass</a></h5>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-47"></a><strong>Req. IDE-47:</strong> <a href="#Req-IDE-47">Superclass</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a class <code>C</code> with a supertype <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi><mo>=</mo><mi>C</mi><mo>.</mo><mi>s</mi><mi>u</mi><mi>p</mi></math>, the following constraints must hold;</p>
</div>
<div class="ulist">
<ul>
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>C</mi><mo>.</mo><mi>s</mi><mi>u</mi><mi>p</mi></math> must reference a class declaration <code>S</code></p>
</li>
<li>
<p><code>S</code> must be be extendable in the project of <code>C</code></p>
</li>
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>C</mi><mo></mo><mi>C</mi><mo>.</mo><mi>s</mi><mi>u</mi><msup><mi>p</mi><mo>+</mo></msup></math></p>
</li>
<li>
<p>All abstract members in <code>S</code> must be accessible from <code>C</code>:</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>M</mi><mo></mo><mi>S</mi><mo>.</mo><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>:</mi><mi>M</mi><mo>.</mo><mi>a</mi><mi>b</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>c</mi><mi>t</mi><mo></mo></math><br>
<code>M</code> is accessible from <code>C</code>.<br>
Note that <code>M</code> need not be an owned member of <code>S</code> and that this constraint applies even if <code>C</code> is abstract).</p>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>All members of superclasses become members of a class.
This is true even if the owning classes are not directly accessible to a class.
The member-specific access control is not changed.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect3 language-n4js">
<h4 id="_interfaces"><a class="anchor" href="#_interfaces"></a><a class="link" href="#_interfaces">5.1.4. Interfaces</a></h4>
<div class="sect4">
<h5 id="_definition-of-interfaces"><a class="anchor" href="#_definition-of-interfaces"></a><a class="link" href="#_definition-of-interfaces">5.1.4.1. Definition of Interfaces</a></h5>
<div class="sect5">
<h6 id="interfaces-syntax"><a class="anchor" href="#interfaces-syntax"></a><a class="link" href="#interfaces-syntax">5.1.4.1.1. Syntax</a></h6>
<div class="listingblock">
<div class="title">Syntax N4 Interface Declaration</div>
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">N4InterfaceDeclaration &lt;Yield&gt;:
=&gt; (
{N4InterfaceDeclaration}
annotations+=Annotation*
(declaredModifiers+=N4Modifier)*
'interface' typingStrategy=TypingStrategyDefSiteOperator? name=BindingIdentifier&lt;Yield&gt;?
)
TypeVariables?
InterfaceImplementsList?
Members&lt;Yield&gt;
;
fragment InterfaceImplementsList*:
'implements' superInterfaceRefs+=ParameterizedTypeRefNominal
(',' superInterfaceRefs+=ParameterizedTypeRefNominal)*
;</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="interfaces-properties"><a class="anchor" href="#interfaces-properties"></a><a class="link" href="#interfaces-properties">5.1.4.1.2. Properties</a></h6>
<div class="paragraph">
<p>These are the additional properties of interfaces, which can be specified by the user:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>superInterfaces</code></dt>
<dd>
<p>Collection of interfaces extended by this interface; empty by default.
Instead of <code>superInterfaces</code>, we simply write <code>interfaces</code>.</p>
</dd>
</dl>
</div>
</div>
<div class="sect5">
<h6 id="interfaces-type-inference"><a class="anchor" href="#interfaces-type-inference"></a><a class="link" href="#interfaces-type-inference">5.1.4.1.3. Type Inference</a></h6>
<div class="paragraph">
<p>The type of an interface declaration <code>I</code> is of type <code>type{I}</code>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mi>Γ</mi><mo></mo><mi>I</mi><mi>:</mi><mstyle mathvariant="monospace"><mtext>type</mtext></mstyle><mfenced close="}" open="{"><mi>I</mi></mfenced></mrow></mfrac></math>
</div>
</div>
</div>
<div class="sect5">
<h6 id="interfaces-semantics"><a class="anchor" href="#interfaces-semantics"></a><a class="link" href="#interfaces-semantics">5.1.4.1.4. Semantics</a></h6>
<div class="paragraph">
<p>Interfaces are used to describe the public <a href="appendix_a_acronyms.html#_acronyms">API</a> of a classifier.
The main requirement is that the instance of an interface, which must be an instance of a class since interfaces cannot have instances, provides all members declared in the interface.
Thus, a (concrete) class implementing an interface must provide implementations for all the fields, methods, getters and setters of the interface (otherwise it the class must be declared abstract).
The implementations have to be provided either directly in the class itself, through a superclass, or by the interface if the member has a default implementation.</p>
</div>
<div class="paragraph">
<p>A field declaration in an interface denotes that all implementing classes can either provide a field of the same name and the same(!) type or corresponding field accessors.
If no such members are defined in the class or a (transitive) superclass, the field is mixed in from the interface automatically.
This is also true for the initializer of the field.</p>
</div>
<div class="paragraph">
<p>All instance methods, getters and setters declared in an interface are implicitly abstract if they do not provide a default implementation.
The modifier <code>abstract</code> is not required, therefore, in the source code.
The following constraints apply:</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-48"></a><strong>Req. IDE-48:</strong> <a href="#Req-IDE-48">Interfaces</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For any interface <code>I</code>, the following must hold:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Interfaces may not be instantiated.</p>
</li>
<li>
<p>Interfaces cannot be set to final (with annotation @Final): <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>¬</mo><mi>I</mi><mo>.</mo><mi>f</mi><mi>i</mi><mi>n</mi><mi>a</mi><mi>l</mi></math>.</p>
</li>
<li>
<p>Members of an interface must not be declared private.
The default access modifier in interfaces is the the type’s visibility or <code>project</code>, if the type’s visibility is <code>private</code>.</p>
</li>
<li>
<p>Members of an interface, except methods, must not be declared <code>@Final</code>:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo></mo><mi>m</mi><mo></mo><mi>I</mi><mo>.</mo><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>:</mi><mi>m</mi><mo>.</mo><mi>f</mi><mi>i</mi><mi>n</mi><mi>a</mi><mi>l</mi><mo></mo><mi>m</mi><mo></mo><mi>I</mi><mo>.</mo><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi></math>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title=""></i>
</td>
<td class="content">
not allowing field accessors to be declared final was a deliberate decision, because it would complicate the internal handling of member redefinition; might be reconsidered at a later time
</td>
</tr>
</table>
</div>
</li>
<li>
<p>The literal may not be used in the initializer expression of a field of an interface.<br>
This restriction is required, because the order of implementation of these fields in an implementing class cannot be guaranteed.
This applies to both instance and static fields in interfaces, but in case of static fields, <code>this</code> is also disallowed due to <a href="#_static-members-of-interfaces">Static Members of Interfaces</a>.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="paragraph">
<p>It is possible to declare members in interfaces with a smaller visibility as the interface itself.
In that case, clients of the interface may be able to use the interface but not to implement it.</p>
</div>
<div class="paragraph">
<p>In order to simplify modeling of runtime types, such as elements, interfaces do not only support the notation of static methods but constant data fields as well.
Since <a href="appendix_a_acronyms.html#_acronyms">IDL</a> [<a href="appendix_c_bibliography.html#OMG14a">OMG14a</a>] is used to describe these elements in specifications (and mapped to JavaScript via rules described in [<a href="appendix_c_bibliography.html#W3C12a">W3C12a</a>])
constant data fields are an often-used technique there and they can be modeled in N4JS 1:1.</p>
</div>
<div class="paragraph">
<p>As specified in <a href="#Req-IDE-56">[Req-IDE-56]</a>, interfaces cannot contain a constructor i.e.<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>m</mi><mo></mo><mi>I</mi><mo>.</mo><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>d</mi><mi>M</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi><mi>:</mi><mi>m</mi><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><msup><mo></mo><mi>'</mi></msup><mi>c</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>u</mi><mi>c</mi><mi>t</mi><mi>o</mi><msup><mi>r</mi><mi>'</mi></msup></math>.</p>
</div>
<div class="exampleblock">
<div class="title">Example 32. Simple Interfaces</div>
<div class="content">
<div class="paragraph">
<p>The following example shows the syntax for defining interfaces.
The second interface extends the first one.
Note that methods are implicitly defined abstract in interfaces.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">interface I {
foo(): void
}
interface I2 extends I {
someText: string;
bar(): void
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>If a classifier <code>C</code> <em>implements</em> an interface <code>I</code>, we say <code>I</code> is <em>implemented</em> by <code>C</code>.
If <code>C</code> redefines members declared in <code>I</code>, we say that these members are <em>implemented</em> by <code>C</code>.
Members not redefined by <code>C</code> but with a default implementations are <em>mixed in</em> or <em>consumed by</em> <code>C</code>.
We all cases we call <code>C</code> the <em>implementor</em>.</p>
</div>
<div class="paragraph">
<p>Besides the general constraints described in <a href="#_common-semantics-of-classifiers">Common Semantics of Classifiers</a>, the following constraints must hold for extending or implementing interfaces:</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-49"></a><strong>Req. IDE-49:</strong> <a href="#Req-IDE-49">Extending Interfaces</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given type
<code>I</code>, and <math xmlns="http://www.w3.org/1998/Math/MathML"><mfenced close="}" open="{"><msub><mi>I</mi><mn>1</mn></msub><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><msub><mi>I</mi><mi>n</mi></msub></mfenced></math> directly extended by <code>I</code>, the following constraints must be true:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Only interfaces can extend interfaces: <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi><mo>,</mo><msub><mi>I</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>I</mi><mi>n</mi></msub></math> must be interfaces.</p>
</li>
<li>
<p>An interface may not directly extend the same interface more than once:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>I</mi><mi>i</mi></msub><mo>=</mo><msub><mi>I</mi><mi>j</mi></msub><mo></mo><mi>i</mi><mo>=</mo><mi>j</mi></math> for any
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi><mo>,</mo><mi>j</mi><mo></mo><mfenced close="}" open="{"><mrow><mn>1</mn><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mi>n</mi></mrow></mfenced></math>.</p>
</li>
<li>
<p>An interface may (indirectly) extend the same interface <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> more than once only if</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> is not parameterized, or</p>
</li>
<li>
<p>in all cases <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> is extended with the same type arguments for all invariant type parameters.<br>
Note that for type parameters of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> that are declared covariant or contravariant on definition site, different type arguments may be used.</p>
</li>
</ol>
</div>
</li>
<li>
<p>All abstract members in <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>I</mi><mi>i</mi></msub></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi><mo></mo><mfenced close="}" open="{"><mn>1</mn><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><mi>n</mi></mfenced></math>, must be accessible from <code>I</code>:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>i</mi><mo></mo><mfenced close="}" open="{"><mn>1</mn><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><mi>n</mi></mfenced><mi>:</mi><mi>M</mi><mo></mo><msub><mi>I</mi><mi>i</mi></msub><mo>.</mo><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi><mo></mo><mi>M</mi><mo>.</mo><mi>a</mi><mi>b</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>c</mi><mi>t</mi><mo></mo></math> <code>M</code> is accessible from <code>I</code>.<br>
Note that <code>M</code> need not be an owned member of <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>I</mi><mi>i</mi></msub></math>.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-50"></a><strong>Req. IDE-50:</strong> <a href="#Req-IDE-50">Implementing Interfaces</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given type
<code>C</code>, and <math xmlns="http://www.w3.org/1998/Math/MathML"><mfenced close="}" open="{"><msub><mi>I</mi><mn>1</mn></msub><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><msub><mi>I</mi><mi>n</mi></msub></mfenced></math> directly implemented
by <code>C</code>, the following constraints must be true:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Only classes can implement interfaces: <code>C</code> must be a Class.</p>
</li>
<li>
<p>A class can only implement interfaces: <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>I</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>I</mi><mi>n</mi></msub></math> must be interfaces.</p>
</li>
<li>
<p>A class may not directly implement the same interface more than once:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>I</mi><mi>i</mi></msub><mo>=</mo><msub><mi>I</mi><mi>j</mi></msub><mo></mo><mi>i</mi><mo>=</mo><mi>j</mi></math> for any <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi><mo>,</mo><mi>j</mi><mo></mo><mfenced close="}" open="{"><mn>1</mn><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><mi>n</mi></mfenced></math>.</p>
</li>
<li>
<p>A class may (indirectly) implement the same interface <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> more than once only if</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> is not parameterized, or</p>
</li>
<li>
<p>in all cases <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> is implemented with the same type arguments for all invariant type parameters.<br>
Note that for type parameters of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> that are declared covariant or contravariant on definition site, different type arguments may be used.</p>
</li>
</ol>
</div>
</li>
<li>
<p>All abstract members in <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>I</mi><mi>i</mi></msub></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi><mo></mo><mfenced close="}" open="{"><mn>1</mn><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><mi>n</mi></mfenced></math>, must be accessible from <code>C</code>:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>i</mi><mo></mo><mfenced close="}" open="{"><mn>1</mn><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><mi>n</mi></mfenced><mi>:</mi><mi>M</mi><mo></mo><msub><mi>I</mi><mi>i</mi></msub><mo>.</mo><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi><mo></mo><mi>M</mi><mo>.</mo><mi>a</mi><mi>b</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>c</mi><mi>t</mi><mo></mo></math> <code>M</code> is accessible from <code>C</code>.<br>
Note that <code>M</code> need not be an owned member of <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>I</mi><mi>i</mi></msub></math>.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="paragraph">
<p>For default methods in interfaces, see <a href="#_default-methods-in-interfaces">Default Methods in Interfaces</a>.</p>
</div>
</div>
</div>
</div>
<div class="sect3 language-n4js">
<h4 id="_generic-classifiers"><a class="anchor" href="#_generic-classifiers"></a><a class="link" href="#_generic-classifiers">5.1.5. Generic Classifiers</a></h4>
<div class="paragraph">
<p>Classifiers can be declared generic by defining a type parameter via <code>type-param</code>.</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="generic_classifiers"></a><strong>Definition:</strong> <a href="#generic_classifiers">Generic Classifiers</a></p>
</div>
<div class="paragraph">
<p>A generic classifier is a classifier with at least one type parameter.
That is, a given classifier <code>C</code> is generic if and only if <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>|</mo><mi>C</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>P</mi><mi>a</mi><mi>r</mi><mi>s</mi><mo>|</mo><mo></mo><mn>1</mn></math>.</p>
</div>
<div class="paragraph">
<p>If a classifier does not define any type parameters, it is not generic, even if its superclass or any implemented interface is generic.</p>
</div>
<div class="paragraph">
<p>The format of the type parameter expression is described in <a href="types.html#_parameterized-types">Parameterized Types</a>.
The type variable defined by the type parameter’s type expression can be used just like a normal type inside the class definition.</p>
</div>
<div class="paragraph">
<p>If using a generic classifier as type of a variable, it may be parameterized.
This is usually done via a type expression (cf. <a href="types.html#_parameterized-types">Parameterized Types</a>) or via <code>typearg</code> in case of supertypes.
If a generic classifier defines multiple type variables, these variables are bound in the order of their definition.
In any case, all type variables have to be bound.
That means in particular that raw types are not allowed. (cf <a href="types.html#_parameterized-types">Parameterized Types</a> for details).</p>
</div>
<div class="paragraph">
<p>If a generic classifier is used as super classifier, the type arguments can be type variables.
Note that the type variable of the super classifier is not lifted, that is to say that all type variables are to be explicitly bound in the type references used in the <code>extend</code>, <code>with</code>, or <code>implements</code> section using <code>typearg</code>.
If a type variable is used in <code>typearg</code> to bound a type variable of a type parameter, it has to fulfil possible type constraints (upper/lower bound) specified in the type parameter.</p>
</div>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 33. Generic Type Definition and Usage as Type of Variable</div>
<div class="content">
<div class="paragraph">
<p>This example demonstrates how to define a generic type and how to refer to it in a variable definition.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">export class Container&lt;T&gt; {
private item: T;
getItem(): T {
return this.item;
}
setItem(item: T): void {
this.item = item;
}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>This type can now be used as a type of a variable as follows</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import Container from "p/Container"
var stringContainer: Container&lt;string&gt; = new Container&lt;string&gt;();
stringContainer.setItem("Hello");
var s: string = stringContainer.getItem();</code></pre>
</div>
</div>
<div class="paragraph">
<p>In line 3, the type variable <code>T</code> of the generic class <code>Container</code> is bound to <code>string</code>.</p>
</div>
<div class="exampleblock">
<div class="title">Example 34. Binding of type variables with multiple types</div>
<div class="content">
<div class="paragraph">
<p>For a given generic class <code>G</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A{}
class B{}
class C extends A{}
class G&lt;S, T extends A, U extends B&gt; {
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>the variable definition</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var x: G&lt;Number,C,B&gt;;</code></pre>
</div>
</div>
<div class="paragraph">
<p>would bind the type variables as follows:</p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 66.6668%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>S</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>Number</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">Bound by first type argument, no bound constraints defined for <code>S</code>.</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>T</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>C</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">Bound by second type argument, <code>C</code> must be a subtype of in order to fulfill the type constraint.</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>U</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>B</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">Bound by third type argument, <code>extends</code> is reflexive, that is <code>B</code> fulfills the
type constraint.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-51"></a><strong>Req. IDE-51:</strong> <a href="#Req-IDE-51">Generic Superclass, Type Argument with Type Variable</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given generic superclass <code>SuperClass</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class SuperClass&lt;S, T extends A, U extends B&gt; {};</code></pre>
</div>
</div>
<div class="paragraph">
<p>and a generic subclass <code>SubClass</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class SubClass&lt;X extends A&gt; extends SuperClass&lt;Number, X, B&gt; {..};</code></pre>
</div>
</div>
<div class="paragraph">
<p>the variable definition</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var s: SubClass&lt;C&gt;;</code></pre>
</div>
</div>
<div class="paragraph">
<p>would bind the type variables as follows:<br></p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 66.6668%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-center valign-top">TypeVariable</th>
<th class="tableblock halign-center valign-top">Bound to</th>
<th class="tableblock halign-center valign-top">Explanation</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>SuperClass.S</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>Number</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Type variable <code>s</code> of supertype <code>SuperClass</code> is bound to <code>Number</code>.</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>SuperClass.T</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>SubClass.X=C</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Type variable <code>T</code> of supertype <code>SuperClass</code> is bound to type variable <code>X</code> of <code>SubClass</code>. It gets
then indirectly bound to <code>C</code> as specified by the type argument of the
variable definition.</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>SuperClass.U</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>B</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Type variable <code>U</code> of supertype <code>SuperClass</code> is auto-bound to <code>C</code> as no explicit binding for the third type variable is specified.</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>SubClass.X</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>C</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Bound by first type argument specified in variable definition.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="sect3 language-n4js">
<h4 id="sec:definition-site-variance"><a class="anchor" href="#sec:definition-site-variance"></a><a class="link" href="#sec:definition-site-variance">5.1.6. Definition-Site Variance</a></h4>
<div class="paragraph">
<p>In addition to use-site declaration of variance in the form of Java-like wildcards, N4JS provides support for definition-site declaration of variance as known from languages such as C# and Scala.</p>
</div>
<div class="paragraph">
<p>The <em>variance</em> of a parameterized type states how its subtyping relates to its type arguments’ subtyping.
For example, given a parameterized type <code>G&lt;T&gt;</code> and plain types <code>A</code> and <code>B</code>, we know</p>
</div>
<div class="ulist">
<ul>
<li>
<p>if <code>G</code> is <strong>covariant</strong> w.r.t. its parameter <code>T</code>, then</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>B</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>A</mtext></mstyle><mo></mo><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>B</mtext></mstyle><mo>&gt;</mo><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>A</mtext></mstyle><mo>&gt;</mo></math></p>
</div>
</li>
<li>
<p>if <code>G</code> is <strong>contravariant</strong> w.r.t. its parameter <code>T</code>, then</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>B</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>A</mtext></mstyle><mo></mo><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>A</mtext></mstyle><mo>&gt;</mo><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>B</mtext></mstyle><mo>&gt;</mo></math></p>
</div>
</li>
<li>
<p>if <code>G</code> is <strong>invariant</strong> w.r.t. its parameter <code>T</code>, then</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>B</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>A</mtext></mstyle><mo></mo><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>A</mtext></mstyle><mo>&gt;</mo><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>B</mtext></mstyle><mo>&gt;</mo></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>B</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>A</mtext></mstyle><mo></mo><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>A</mtext></mstyle><mo>&gt;</mo><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>B</mtext></mstyle><mo>&gt;</mo></math></p>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>Note that variance is declared per type parameter, so a single parameterized type with more than one type parameter may be, for example, covariant w.r.t. one type parameter and contravariant w.r.t. another.</p>
</div>
<div class="paragraph">
<p>Strictly speaking, a type parameter/variable itself is not co- or contravariant;<br>
however, for the sake of simplicity we say <em><code>T</code> is covariant</em> as a short form for <em><code>G</code> is covariant with respect to its type parameter <code>T</code></em> (for contravariant and invariant accordingly).</p>
</div>
<div class="paragraph">
<p>To declare the variance of a parameterized classifier on definition site, simply add keyword <code>in</code> or <code>out</code> before the corresponding type parameter:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class ReadOnlyList&lt;out T&gt; { // covariance
// ...
}
interface Consumer&lt;in T&gt; { // contravariance
// ...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In such cases, the following constraints apply.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-174"></a><strong>Req. IDE-174:</strong> <a href="#Req-IDE-174">Definition-Site Variance</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Given a parameterized type with a type parameter , the following must hold:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><code>T</code> may only appear in variance-compatible positions:</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>if <code>T</code> is declared on definition site to be <strong>covariant</strong>, then it may only appear in covariant positions within the type’s non-private member declarations.</p>
</li>
<li>
<p>if <code>T</code> is declared on definition site to be <strong>contravariant</strong>, then it may only appear in contravariant positions within the type’s non-private member declarations.</p>
</li>
<li>
<p>if <code>T</code> is <strong>invariant</strong>, i.e. neither declared covariant nor declared contravariant on definition site, then it may appear in any position (where type variables are allowed).</p>
<div class="paragraph">
<p>Thus, no restrictions apply within the declaration of private members and within the body of field accessors and methods.</p>
</div>
</li>
</ol>
</div>
</li>
<li>
<p>definition-site variance may not be combined with incompatible use-site variance:</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>if <code>T</code> is declared on definition site to be <strong>covariant</strong>, then no wildcard with a <strong>lower</strong> bound may be provided as type argument for <code>T</code>.</p>
</li>
<li>
<p>if <code>T</code> is declared on definition site to be <strong>contravariant</strong>, then no wildcard with an <strong>upper</strong> bound may be provided as type argument for <code>T</code>.</p>
</li>
<li>
<p>if <code>T</code> is <strong>invariant</strong>, i.e. neither declared covariant nor declared contravariant on definition site, then any kind of wildcard may be provided as type argument.</p>
<div class="paragraph">
<p>Unbounded wildcards are allowed in all cases.</p>
</div>
</li>
</ol>
</div>
</li>
</ol>
</div>
</div>
</div>
<div id="ex:use-site-declaration-variance" class="exampleblock">
<div class="title">Example 35. Use-site declaration of variance</div>
<div class="content">
<div class="paragraph">
<p>For illustration purposes, let’s compare use-site and definition-site declaration of variance.
Since use-site variance is more familiar to the Java developer, we start with this flavor.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class Person {
name: string;
}
class Employee extends Person {}
interface List&lt;T&gt; {
add(elem: T)
read(idx: int): T
}
function getNameOfFirstPerson(list: List&lt;? extends Person&gt;): string {
return list.read(0).name;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Function <code>getNameOfFirstPerson</code> below takes a list and returns the name of the first person in the list.
Since it never adds new elements to the given list, it could accept <code>List</code>s of any subtype of <code>Person</code>, for example a <code>List&lt;Employee&gt;</code>.
To allow this, its formal parameter has a type of <code>List&lt;? extends Person&gt;</code> instead of <code>List&lt;Person&gt;</code>.
Such use-site variance is useful whenever an invariant type, like <code>List</code> above, is being used in a way such that it can be treated as if it were co- or contravariant.</p>
</div>
<div class="paragraph">
<p>Sometimes, however, we are dealing with types that are inherently covariant or contravariant, for example an <code>ImmutableList</code> from which we can only read elements would be covariant.
In such a case, use-site declaration of variance is tedious and error-prone: we would have to declare the variance wherever the type is being used and would have to
make sure not to forget the declaration or otherwise limit the flexibility and reusability of the code (for example, in the above code we could not call <code>getNameOfFirstPerson</code> with a <code>List&lt;Employee&gt;</code>).</p>
</div>
<div class="paragraph">
<p>The solution is to declare the variance on declaration site, as in the following code sample:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">interface ImmutableList&lt;out T&gt; {
// add(elem: T) // error: such a method would now be disallowed
read(idx: int): T
}
function getNameOfFirstPerson2(list: ImmutableList&lt;Person&gt;): string {
return list.read(0).name;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now we can invoke <code>getNameOfFirstPerson2</code> with a <code>List&lt;Employee&gt;</code> even though the implementor of <code>getNameOfFirstPerson2</code> did not add a
use-site declaration of covariance, because the type <code>ImmutableList</code> is declared to be covariant with respect to its parameter <code>T</code>, and this applies globally
throughout the program.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_members"><a class="anchor" href="#_members"></a><a class="link" href="#_members">5.2. Members</a></h3>
<div class="paragraph">
<p>A member is either a method (which may be a special constructor function), a data field, or a getter or a setter.
The latter two implicitly define an accessor field.
Similar to object literals, there must be no data field with the same name as a getter or setter.</p>
</div>
<div class="paragraph">
<p>(overriding, implementation and consumption) is
described in <a href="#_redefinition-of-members">Redefinition of Members</a>.</p>
</div>
<div class="sect3 language-n4js">
<h4 id="_syntax-4"><a class="anchor" href="#_syntax-4"></a><a class="link" href="#_syntax-4">5.2.1. Syntax</a></h4>
<div class="listingblock">
<div class="title">Syntax N4JS member access modifier</div>
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">enum N4JSMemberAccessModifier: private | project | protected | public;
N4MemberDeclaration: N4MethodDeclaration | N4FieldDeclaration | N4GetterDeclaration | N4SetterDeclaration;</code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_properties-3"><a class="anchor" href="#_properties-3"></a><a class="link" href="#_properties-3">5.2.1.1. Properties</a></h5>
<div class="paragraph">
<p>Members share the following properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>annotations</code> </dt>
<dd>
<p>Arbitrary annotations, see <a href="annotations.html#_annotations">Annotations</a> for details.</p>
</dd>
<dt class="hdlist1"><code>accessModifier</code> </dt>
<dd>
<p>N4JS member access modifier: <code>private</code>, <code>project</code>, <code>potected</code>, or <code>public</code>; the latter two can be combined with <code>@Internal</code>; default is <code>project</code> for classes and private interfaces.
For a non-private interface defaults to the interface’s visibility.</p>
</dd>
<dt class="hdlist1"><code>name</code> </dt>
<dd>
<p>The simple name of the member, that is an identifier name (cf. <a href="names.html#_valid-names">Valid Names</a>).</p>
</dd>
<dt class="hdlist1"><code>static</code> </dt>
<dd>
<p>Boolean property to distinguish instance from classifier members, see <a href="#_static-members">Static Members</a>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>The following pseudo properties are defined via annotations:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>deprecated</code> </dt>
<dd>
<p>Boolean property set to true if annotation <code>@Deprecated</code> is set. <sup class="footnote">[<a id="_footnoteref_29" class="footnote" href="appendix_c_bibliography.html#_footnote_29" title="View footnote.">29</a>]</sup></p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>And we additionally define the following pseudo properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>acc</code> </dt>
<dd>
<p>Member access modifier as described in <a href="names.html#_accessibility-of-members">Accessibility of Members</a>, it is the aggregated value of
the <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>a</mi><mi>c</mi><mi>c</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi>M</mi><mi>o</mi><mi>d</mi><mi>i</mi><mi>f</mi><mi>i</mi><mi>e</mi><mi>r</mi></math> and the <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>e</mi><mi>x</mi><mi>p</mi><mi>o</mi><mi>r</mi><mi>t</mi></math> property.</p>
</dd>
<dt class="hdlist1"><code>owner</code> </dt>
<dd>
<p>Owner classifier of the member.</p>
</dd>
<dt class="hdlist1"><code>typeRef</code> </dt>
<dd>
<p>Type of the member—this is the type of a field or the type of the method which is a function type (and not the return type).</p>
</dd>
<dt class="hdlist1"><code>assignability</code> </dt>
<dd>
<p>Enumeration, may be one of the following values:</p>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>set</code></dt>
<dd>
<p>Member may only be set, i.e. it could only be used on the left hand side of an assignment.</p>
</dd>
<dt class="hdlist1"><code>get</code></dt>
<dd>
<p>Member may only be retrieved, i.e. it could only be used on the right hand side of an assignment. This is the default setting for methods.</p>
</dd>
<dt class="hdlist1"><code>any</code></dt>
<dd>
<p> Member may be set or retrieved, i.e. it could only be used on the left or right hand side of an assignment.
This is the default setting for fields.</p>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title=""></i>
</td>
<td class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>a</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>g</mi><mi>n</mi><mi>a</mi><mi>b</mi><mi>i</mi><mi>l</mi><mi>i</mi><mi>t</mi><mi>y</mi></math> is related but not equal to writable modifiers used for fields.
We define a partial order on this enumeration as follows:<br>
</td>
</tr>
</table>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo>&lt;</mo><mfenced close=")" open="("><mi>l</mi><mi>r</mi></mfenced><mspace width="3.0mm"/><mi>:</mi><mi>:</mi><mo>=</mo><mspace width="3.0mm"/><mfenced close="}" open="{"><mfenced close=")" open="("><mstyle mathvariant="monospace"><mtext>set</mtext></mstyle><mstyle mathvariant="monospace"><mtext>any</mtext></mstyle></mfenced><mfenced close=")" open="("><mstyle mathvariant="monospace"><mtext>get</mtext></mstyle><mstyle mathvariant="monospace"><mtext>any</mtext></mstyle></mfenced></mfenced></math>
</div>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>abstract</code> </dt>
<dd>
<p>All members have a flag <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>a</mi><mi>b</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>c</mi><mi>t</mi></math>, which is user-defined for methods, getters and setter, but which is always false for fields.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>The following pseudo property is set to make fields compatible with properties of an object literal, however it cannot be changed:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>configurable</code> </dt>
<dd>
<p>Boolean flag reflecting the property descriptor <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mi>o</mi><mi>n</mi><mi>f</mi><mi>i</mi><mi>g</mi><mi>u</mi><mi>r</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi></math>, this is always set to false for members.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_semantics-3"><a class="anchor" href="#_semantics-3"></a><a class="link" href="#_semantics-3">5.2.2. Semantics</a></h4>
<div class="paragraph">
<p>The members of a given classifier <code>C</code> must be named such that the following constraints are met:</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-52"></a><strong>Req. IDE-52:</strong> <a href="#Req-IDE-52">Member Names</a> (ver. 1)</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The name of a member is given as an identifier, a string literal, a numeric literal, or as a computed property name with a compile-time expression (see <a href="expressions.html#compile-time-expressions">Compile-Time Expressions</a>). In particular, string literals, e.g. <code>['myProp']</code>, built-in symbols, e.g. <code>[Symbol.iterator]</code>, and literals of <code>@StringBased</code> enums are all valid computed property names.</p>
</li>
<li>
<p>No two members may have the same name, except one is static and the
other is non-static:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mo></mo><msub><mi>m</mi><mn>1</mn></msub><mo>,</mo><msub><mi>m</mi><mn>2</mn></msub><mo></mo><mi>C</mi><mo>.</mo><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>d</mi><mi>M</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi><mo>,</mo><msub><mi>m</mi><mn>1</mn></msub><mo></mo><msub><mi>m</mi><mn>2</mn></msub><mi>:</mi><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo></mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo></mo><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>s</mi><mi>t</mi><mi>a</mi><mi>t</mi><mi>i</mi><mi>c</mi><mo></mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>s</mi><mi>t</mi><mi>a</mi><mi>t</mi><mi>i</mi><mi>c</mi></mtd></mtr></mtable></math>
</div>
</div>
</li>
<li>
<p>The member name must be a valid identifier name, see <a href="grammar.html#_identifier-names-and-identifiers">Identifier Grammar</a>.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="paragraph">
<p>Thus, over<em>loading</em> of methods is not supported <sup class="footnote">[<a id="_footnoteref_30" class="footnote" href="appendix_c_bibliography.html#_footnote_30" title="View footnote.">30</a>]</sup> and no field may have the same name as a method.
However, over<em>