the java language specificationptgmedia.pearsoncmg.com/images/9780133900699/... · the java ®...

70

Upload: others

Post on 16-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 2: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® LanguageSpecification

Java SE 8 Edition

Page 3: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

This page intentionally left blank

Page 4: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® LanguageSpecification

Java SE 8 Edition

James GoslingBill Joy

Guy SteeleGilad BrachaAlex Buckley

Upper Saddle River, NJ • Boston • Indianapolis • San FranciscoNew York • Toronto • Montreal • London • Munich • Paris • Madrid

Capetown • Sydney • Tokyo • Singapore • Mexico City

Page 5: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

Copyright © 1997, 2014, Oracle and/or its affiliates. All rights reserved.500 Oracle Parkway, Redwood City, California 94065, U.S.A.

Many of the designations used by manufacturers and sellers to distinguish their products areclaimed as trademarks. Where those designations appear in this book, and the publisher wasaware of a trademark claim, the designations have been printed with initial capital lettersor in all capitals.

Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names maybe trademarks of their respective owners.

The authors and publisher have taken care in the preparation of this book, but make noexpressed or implied warranty of any kind and assume no responsibility for errors oromissions. No liability is assumed for incidental or consequential damages in connectionwith or arising out of the use of the information or programs contained herein.

This document is provided for information purposes only and the contents hereof are subjectto change without notice. This document is not warranted to be error-free, nor subject toany other warranties or conditions, whether expressed orally or implied in law, includingimplied warranties and conditions of merchantability or fitness for a particular purpose.We specifically disclaim any liability with respect to this document and no contractualobligations are formed either directly or indirectly by this document, except as specified inthe Limited License Grant herein at Appendix A. This document is subject to the LimitedLicense Grant included herein as Appendix A, and may otherwise not be reproduced ortransmitted in any form or by any means, electronic or mechanical, for any purpose, withoutour prior written permission.

The publisher offers excellent discounts on this book when ordered in quantity for bulkpurchases or special sales, which may include electronic versions and/or custom coversand content particular to your business, training goals, marketing focus, and brandinginterests. For more information, please contact U.S. Corporate and Government Sales, (800)382-3419, [email protected]. For sales outside the United States,please contact International Sales, [email protected].

Visit us on the Web: informit.com/aw

Library of Congress Control Number: 2014936248ISBN-13: 978-0-13-390069-9ISBN-10: 0-13-390069-X

Printed in the United States of America. This publication is protected by copyright, andpermission must be obtained from the publisher prior to any prohibited reproduction,storage in a retrieval system, or transmission in any form or by any means, electronic,mechanical, photocopying, recording, or likewise. To obtain permission to use materialfrom this work, please submit a written request to Pearson Education, Inc., PermissionsDepartment, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax yourrequest to (201) 236-3290.

The Specification provided herein is provided to you only under the Limited License Grantincluded herein as Appendix A. Please see Appendix A.

Text printed in the United States on recycled paper at Edwards Brothers Malloy in AnnArbor, Michigan. First printing, May 2014.

Page 6: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

To Maurizio, with deepest thanks.

Page 7: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

This page intentionally left blank

Page 8: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

vii

Table of Contents

Preface to the Java SE 8 Edition xxi

1 Introduction 11.1 Organization of the Specification 21.2 Example Programs 61.3 Notation 61.4 Relationship to Predefined Classes and Interfaces 71.5 Feedback 71.6 References 7

2 Grammars 92.1 Context-Free Grammars 92.2 The Lexical Grammar 92.3 The Syntactic Grammar 102.4 Grammar Notation 10

3 Lexical Structure 153.1 Unicode 153.2 Lexical Translations 163.3 Unicode Escapes 173.4 Line Terminators 193.5 Input Elements and Tokens 193.6 White Space 203.7 Comments 213.8 Identifiers 223.9 Keywords 243.10 Literals 24

3.10.1 Integer Literals 253.10.2 Floating-Point Literals 313.10.3 Boolean Literals 343.10.4 Character Literals 343.10.5 String Literals 353.10.6 Escape Sequences for Character and String Literals 373.10.7 The Null Literal 38

3.11 Separators 383.12 Operators 38

Page 9: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

viii

4 Types, Values, and Variables 414.1 The Kinds of Types and Values 414.2 Primitive Types and Values 42

4.2.1 Integral Types and Values 434.2.2 Integer Operations 434.2.3 Floating-Point Types, Formats, and Values 454.2.4 Floating-Point Operations 484.2.5 The boolean Type and boolean Values 51

4.3 Reference Types and Values 524.3.1 Objects 534.3.2 The Class Object 554.3.3 The Class String 564.3.4 When Reference Types Are the Same 56

4.4 Type Variables 574.5 Parameterized Types 59

4.5.1 Type Arguments of Parameterized Types 604.5.2 Members and Constructors of Parameterized Types 63

4.6 Type Erasure 644.7 Reifiable Types 644.8 Raw Types 664.9 Intersection Types 704.10 Subtyping 71

4.10.1 Subtyping among Primitive Types 714.10.2 Subtyping among Class and Interface Types 714.10.3 Subtyping among Array Types 734.10.4 Least Upper Bound 73

4.11 Where Types Are Used 754.12 Variables 80

4.12.1 Variables of Primitive Type 814.12.2 Variables of Reference Type 814.12.3 Kinds of Variables 834.12.4 final Variables 854.12.5 Initial Values of Variables 874.12.6 Types, Classes, and Interfaces 88

5 Conversions and Contexts 915.1 Kinds of Conversion 94

5.1.1 Identity Conversion 945.1.2 Widening Primitive Conversion 945.1.3 Narrowing Primitive Conversion 965.1.4 Widening and Narrowing Primitive Conversion 995.1.5 Widening Reference Conversion 995.1.6 Narrowing Reference Conversion 995.1.7 Boxing Conversion 1005.1.8 Unboxing Conversion 1025.1.9 Unchecked Conversion 1035.1.10 Capture Conversion 103

Page 10: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

ix

5.1.11 String Conversion 1055.1.12 Forbidden Conversions 1065.1.13 Value Set Conversion 106

5.2 Assignment Contexts 1075.3 Invocation Contexts 1125.4 String Contexts 1145.5 Casting Contexts 114

5.5.1 Reference Type Casting 1175.5.2 Checked Casts and Unchecked Casts 1215.5.3 Checked Casts at Run Time 122

5.6 Numeric Contexts 1245.6.1 Unary Numeric Promotion 1245.6.2 Binary Numeric Promotion 125

6 Names 1296.1 Declarations 1306.2 Names and Identifiers 1376.3 Scope of a Declaration 1396.4 Shadowing and Obscuring 142

6.4.1 Shadowing 1446.4.2 Obscuring 147

6.5 Determining the Meaning of a Name 1486.5.1 Syntactic Classification of a Name According to Context 1496.5.2 Reclassification of Contextually Ambiguous Names 1526.5.3 Meaning of Package Names 154

6.5.3.1 Simple Package Names 1556.5.3.2 Qualified Package Names 155

6.5.4 Meaning of PackageOrTypeNames 1556.5.4.1 Simple PackageOrTypeNames 1556.5.4.2 Qualified PackageOrTypeNames 155

6.5.5 Meaning of Type Names 1556.5.5.1 Simple Type Names 1566.5.5.2 Qualified Type Names 156

6.5.6 Meaning of Expression Names 1566.5.6.1 Simple Expression Names 1566.5.6.2 Qualified Expression Names 157

6.5.7 Meaning of Method Names 1606.5.7.1 Simple Method Names 160

6.6 Access Control 1616.6.1 Determining Accessibility 1626.6.2 Details on protected Access 166

6.6.2.1 Access to a protected Member 1676.6.2.2 Qualified Access to a protected Constructor 167

6.7 Fully Qualified Names and Canonical Names 169

7 Packages 1737.1 Package Members 173

Page 11: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

x

7.2 Host Support for Packages 1757.3 Compilation Units 1777.4 Package Declarations 178

7.4.1 Named Packages 1787.4.2 Unnamed Packages 1797.4.3 Observability of a Package 179

7.5 Import Declarations 1807.5.1 Single-Type-Import Declarations 1807.5.2 Type-Import-on-Demand Declarations 1837.5.3 Single-Static-Import Declarations 1847.5.4 Static-Import-on-Demand Declarations 184

7.6 Top Level Type Declarations 185

8 Classes 1898.1 Class Declarations 191

8.1.1 Class Modifiers 1918.1.1.1 abstract Classes 1928.1.1.2 final Classes 1948.1.1.3 strictfp Classes 194

8.1.2 Generic Classes and Type Parameters 1948.1.3 Inner Classes and Enclosing Instances 1978.1.4 Superclasses and Subclasses 2008.1.5 Superinterfaces 2028.1.6 Class Body and Member Declarations 205

8.2 Class Members 2068.3 Field Declarations 211

8.3.1 Field Modifiers 2158.3.1.1 static Fields 2168.3.1.2 final Fields 2198.3.1.3 transient Fields 2198.3.1.4 volatile Fields 220

8.3.2 Field Initialization 2218.3.3 Forward References During Field Initialization 222

8.4 Method Declarations 2258.4.1 Formal Parameters 2268.4.2 Method Signature 2308.4.3 Method Modifiers 231

8.4.3.1 abstract Methods 2328.4.3.2 static Methods 2338.4.3.3 final Methods 2348.4.3.4 native Methods 2358.4.3.5 strictfp Methods 2358.4.3.6 synchronized Methods 235

8.4.4 Generic Methods 2378.4.5 Method Result 2378.4.6 Method Throws 2388.4.7 Method Body 240

Page 12: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xi

8.4.8 Inheritance, Overriding, and Hiding 2408.4.8.1 Overriding (by Instance Methods) 2418.4.8.2 Hiding (by Class Methods) 2458.4.8.3 Requirements in Overriding and Hiding 2468.4.8.4 Inheriting Methods with Override-Equivalent

Signatures 2508.4.9 Overloading 250

8.5 Member Type Declarations 2548.5.1 Static Member Type Declarations 254

8.6 Instance Initializers 2558.7 Static Initializers 2558.8 Constructor Declarations 256

8.8.1 Formal Parameters 2578.8.2 Constructor Signature 2588.8.3 Constructor Modifiers 2588.8.4 Generic Constructors 2598.8.5 Constructor Throws 2598.8.6 The Type of a Constructor 2598.8.7 Constructor Body 259

8.8.7.1 Explicit Constructor Invocations 2608.8.8 Constructor Overloading 2648.8.9 Default Constructor 2658.8.10 Preventing Instantiation of a Class 266

8.9 Enum Types 2668.9.1 Enum Constants 2678.9.2 Enum Body Declarations 2688.9.3 Enum Members 271

9 Interfaces 2779.1 Interface Declarations 278

9.1.1 Interface Modifiers 2789.1.1.1 abstract Interfaces 2799.1.1.2 strictfp Interfaces 279

9.1.2 Generic Interfaces and Type Parameters 2799.1.3 Superinterfaces and Subinterfaces 2809.1.4 Interface Body and Member Declarations 282

9.2 Interface Members 2829.3 Field (Constant) Declarations 283

9.3.1 Initialization of Fields in Interfaces 2859.4 Method Declarations 286

9.4.1 Inheritance and Overriding 2879.4.1.1 Overriding (by Instance Methods) 2889.4.1.2 Requirements in Overriding 2899.4.1.3 Inheriting Methods with Override-Equivalent

Signatures 2899.4.2 Overloading 2909.4.3 Interface Method Body 291

Page 13: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xii

9.5 Member Type Declarations 2919.6 Annotation Types 292

9.6.1 Annotation Type Elements 2939.6.2 Defaults for Annotation Type Elements 2979.6.3 Repeatable Annotation Types 2989.6.4 Predefined Annotation Types 302

9.6.4.1 @Target 3029.6.4.2 @Retention 3039.6.4.3 @Inherited 3049.6.4.4 @Override 3049.6.4.5 @SuppressWarnings 3059.6.4.6 @Deprecated 3069.6.4.7 @SafeVarargs 3079.6.4.8 @Repeatable 3089.6.4.9 @FunctionalInterface 308

9.7 Annotations 3089.7.1 Normal Annotations 3099.7.2 Marker Annotations 3119.7.3 Single-Element Annotations 3129.7.4 Where Annotations May Appear 3139.7.5 Multiple Annotations of the Same Type 318

9.8 Functional Interfaces 3199.9 Function Types 323

10 Arrays 32910.1 Array Types 33010.2 Array Variables 33010.3 Array Creation 33210.4 Array Access 33210.5 Array Store Exception 33310.6 Array Initializers 33510.7 Array Members 33610.8 Class Objects for Arrays 33810.9 An Array of Characters Is Not a String 339

11 Exceptions 34111.1 The Kinds and Causes of Exceptions 342

11.1.1 The Kinds of Exceptions 34211.1.2 The Causes of Exceptions 34311.1.3 Asynchronous Exceptions 343

11.2 Compile-Time Checking of Exceptions 34411.2.1 Exception Analysis of Expressions 34611.2.2 Exception Analysis of Statements 34611.2.3 Exception Checking 347

11.3 Run-Time Handling of an Exception 349

Page 14: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xiii

12 Execution 35312.1 Java Virtual Machine Startup 353

12.1.1 Load the Class Test 35412.1.2 Link Test: Verify, Prepare, (Optionally) Resolve 35412.1.3 Initialize Test: Execute Initializers 35512.1.4 Invoke Test.main 356

12.2 Loading of Classes and Interfaces 35612.2.1 The Loading Process 357

12.3 Linking of Classes and Interfaces 35812.3.1 Verification of the Binary Representation 35812.3.2 Preparation of a Class or Interface Type 35912.3.3 Resolution of Symbolic References 359

12.4 Initialization of Classes and Interfaces 36012.4.1 When Initialization Occurs 36112.4.2 Detailed Initialization Procedure 363

12.5 Creation of New Class Instances 36512.6 Finalization of Class Instances 369

12.6.1 Implementing Finalization 37012.6.2 Interaction with the Memory Model 372

12.7 Unloading of Classes and Interfaces 37312.8 Program Exit 374

13 Binary Compatibility 37513.1 The Form of a Binary 37613.2 What Binary Compatibility Is and Is Not 38213.3 Evolution of Packages 38313.4 Evolution of Classes 383

13.4.1 abstract Classes 38313.4.2 final Classes 38313.4.3 public Classes 38413.4.4 Superclasses and Superinterfaces 38413.4.5 Class Type Parameters 38513.4.6 Class Body and Member Declarations 38613.4.7 Access to Members and Constructors 38713.4.8 Field Declarations 38813.4.9 final Fields and static Constant Variables 39113.4.10 static Fields 39313.4.11 transient Fields 39313.4.12 Method and Constructor Declarations 39413.4.13 Method and Constructor Type Parameters 39413.4.14 Method and Constructor Formal Parameters 39513.4.15 Method Result Type 39613.4.16 abstract Methods 39613.4.17 final Methods 39713.4.18 native Methods 39713.4.19 static Methods 39813.4.20 synchronized Methods 398

Page 15: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xiv

13.4.21 Method and Constructor Throws 39813.4.22 Method and Constructor Body 39813.4.23 Method and Constructor Overloading 39913.4.24 Method Overriding 40013.4.25 Static Initializers 40013.4.26 Evolution of Enums 400

13.5 Evolution of Interfaces 40013.5.1 public Interfaces 40013.5.2 Superinterfaces 40113.5.3 Interface Members 40113.5.4 Interface Type Parameters 40113.5.5 Field Declarations 40213.5.6 Interface Method Declarations 40213.5.7 Evolution of Annotation Types 403

14 Blocks and Statements 40514.1 Normal and Abrupt Completion of Statements 40514.2 Blocks 40714.3 Local Class Declarations 40714.4 Local Variable Declaration Statements 408

14.4.1 Local Variable Declarators and Types 40914.4.2 Execution of Local Variable Declarations 410

14.5 Statements 41014.6 The Empty Statement 41214.7 Labeled Statements 41314.8 Expression Statements 41414.9 The if Statement 415

14.9.1 The if-then Statement 41514.9.2 The if-then-else Statement 416

14.10 The assert Statement 41614.11 The switch Statement 41914.12 The while Statement 423

14.12.1 Abrupt Completion of while Statement 42414.13 The do Statement 424

14.13.1 Abrupt Completion of do Statement 42514.14 The for Statement 426

14.14.1 The basic for Statement 42614.14.1.1 Initialization of for Statement 42714.14.1.2 Iteration of for Statement 42714.14.1.3 Abrupt Completion of for Statement 428

14.14.2 The enhanced for statement 42914.15 The break Statement 43214.16 The continue Statement 43414.17 The return Statement 43614.18 The throw Statement 43714.19 The synchronized Statement 43914.20 The try statement 440

Page 16: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xv

14.20.1 Execution of try-catch 44414.20.2 Execution of try-finally and try-catch-finally 44514.20.3 try-with-resources 447

14.20.3.1 Basic try-with-resources 44814.20.3.2 Extended try-with-resources 451

14.21 Unreachable Statements 452

15 Expressions 45915.1 Evaluation, Denotation, and Result 45915.2 Forms of Expressions 46015.3 Type of an Expression 46115.4 FP-strict Expressions 46215.5 Expressions and Run-Time Checks 46215.6 Normal and Abrupt Completion of Evaluation 46415.7 Evaluation Order 466

15.7.1 Evaluate Left-Hand Operand First 46615.7.2 Evaluate Operands before Operation 46815.7.3 Evaluation Respects Parentheses and Precedence 46915.7.4 Argument Lists are Evaluated Left-to-Right 47015.7.5 Evaluation Order for Other Expressions 471

15.8 Primary Expressions 47115.8.1 Lexical Literals 47215.8.2 Class Literals 47315.8.3 this 47415.8.4 Qualified this 47515.8.5 Parenthesized Expressions 475

15.9 Class Instance Creation Expressions 47615.9.1 Determining the Class being Instantiated 47815.9.2 Determining Enclosing Instances 48015.9.3 Choosing the Constructor and its Arguments 48115.9.4 Run-Time Evaluation of Class Instance Creation

Expressions 48415.9.5 Anonymous Class Declarations 485

15.9.5.1 Anonymous Constructors 48515.10 Array Creation and Access Expressions 487

15.10.1 Array Creation Expressions 48715.10.2 Run-Time Evaluation of Array Creation Expressions 48815.10.3 Array Access Expressions 49115.10.4 Run-Time Evaluation of Array Access Expressions 492

15.11 Field Access Expressions 49415.11.1 Field Access Using a Primary 49415.11.2 Accessing Superclass Members using super 497

15.12 Method Invocation Expressions 49915.12.1 Compile-Time Step 1: Determine Class or Interface to

Search 50015.12.2 Compile-Time Step 2: Determine Method Signature 502

15.12.2.1 Identify Potentially Applicable Methods 509

Page 17: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xvi

15.12.2.2 Phase 1: Identify Matching Arity Methods Applicableby Strict Invocation 511

15.12.2.3 Phase 2: Identify Matching Arity Methods Applicableby Loose Invocation 512

15.12.2.4 Phase 3: Identify Methods Applicable by Variable ArityInvocation 513

15.12.2.5 Choosing the Most Specific Method 51415.12.2.6 Method Invocation Type 516

15.12.3 Compile-Time Step 3: Is the Chosen Method Appropriate? 51715.12.4 Run-Time Evaluation of Method Invocation 520

15.12.4.1 Compute Target Reference (If Necessary) 52015.12.4.2 Evaluate Arguments 52215.12.4.3 Check Accessibility of Type and Method 52315.12.4.4 Locate Method to Invoke 52415.12.4.5 Create Frame, Synchronize, Transfer Control 528

15.13 Method Reference Expressions 52915.13.1 Compile-Time Declaration of a Method Reference 53215.13.2 Type of a Method Reference 53715.13.3 Run-Time Evaluation of Method References 539

15.14 Postfix Expressions 54215.14.1 Expression Names 54315.14.2 Postfix Increment Operator ++ 54315.14.3 Postfix Decrement Operator -- 544

15.15 Unary Operators 54415.15.1 Prefix Increment Operator ++ 54615.15.2 Prefix Decrement Operator -- 54615.15.3 Unary Plus Operator + 54715.15.4 Unary Minus Operator - 54715.15.5 Bitwise Complement Operator ~ 54815.15.6 Logical Complement Operator ! 548

15.16 Cast Expressions 54915.17 Multiplicative Operators 550

15.17.1 Multiplication Operator * 55115.17.2 Division Operator / 55215.17.3 Remainder Operator % 554

15.18 Additive Operators 55615.18.1 String Concatenation Operator + 55715.18.2 Additive Operators (+ and -) for Numeric Types 559

15.19 Shift Operators 56115.20 Relational Operators 562

15.20.1 Numerical Comparison Operators <, <=, >, and >= 56315.20.2 Type Comparison Operator instanceof 564

15.21 Equality Operators 56515.21.1 Numerical Equality Operators == and != 56615.21.2 Boolean Equality Operators == and != 56715.21.3 Reference Equality Operators == and != 567

15.22 Bitwise and Logical Operators 56815.22.1 Integer Bitwise Operators &, ^, and | 568

Page 18: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xvii

15.22.2 Boolean Logical Operators &, ^, and | 56915.23 Conditional-And Operator && 57015.24 Conditional-Or Operator || 57015.25 Conditional Operator ? : 571

15.25.1 Boolean Conditional Expressions 57915.25.2 Numeric Conditional Expressions 57915.25.3 Reference Conditional Expressions 580

15.26 Assignment Operators 58115.26.1 Simple Assignment Operator = 58215.26.2 Compound Assignment Operators 588

15.27 Lambda Expressions 59415.27.1 Lambda Parameters 59615.27.2 Lambda Body 59915.27.3 Type of a Lambda Expression 60215.27.4 Run-Time Evaluation of Lambda Expressions 604

15.28 Constant Expressions 605

16 Definite Assignment 60716.1 Definite Assignment and Expressions 613

16.1.1 Boolean Constant Expressions 61316.1.2 Conditional-And Operator && 61316.1.3 Conditional-Or Operator || 61416.1.4 Logical Complement Operator ! 61416.1.5 Conditional Operator ? : 61416.1.6 Conditional Operator ? : 61516.1.7 Other Expressions of Type boolean 61516.1.8 Assignment Expressions 61516.1.9 Operators ++ and -- 61616.1.10 Other Expressions 616

16.2 Definite Assignment and Statements 61716.2.1 Empty Statements 61716.2.2 Blocks 61716.2.3 Local Class Declaration Statements 61916.2.4 Local Variable Declaration Statements 61916.2.5 Labeled Statements 61916.2.6 Expression Statements 62016.2.7 if Statements 62016.2.8 assert Statements 62016.2.9 switch Statements 62116.2.10 while Statements 62116.2.11 do Statements 62216.2.12 for Statements 622

16.2.12.1 Initialization Part of for Statement 62316.2.12.2 Incrementation Part of for Statement 623

16.2.13 break, continue, return, and throw Statements 62416.2.14 synchronized Statements 62416.2.15 try Statements 624

Page 19: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xviii

16.3 Definite Assignment and Parameters 62616.4 Definite Assignment and Array Initializers 62616.5 Definite Assignment and Enum Constants 62616.6 Definite Assignment and Anonymous Classes 62716.7 Definite Assignment and Member Types 62716.8 Definite Assignment and Static Initializers 62816.9 Definite Assignment, Constructors, and Instance Initializers 628

17 Threads and Locks 63117.1 Synchronization 63217.2 Wait Sets and Notification 632

17.2.1 Wait 63317.2.2 Notification 63417.2.3 Interruptions 63517.2.4 Interactions of Waits, Notification, and Interruption 635

17.3 Sleep and Yield 63617.4 Memory Model 637

17.4.1 Shared Variables 64017.4.2 Actions 64017.4.3 Programs and Program Order 64117.4.4 Synchronization Order 64217.4.5 Happens-before Order 64317.4.6 Executions 64617.4.7 Well-Formed Executions 64717.4.8 Executions and Causality Requirements 64717.4.9 Observable Behavior and Nonterminating Executions 650

17.5 final Field Semantics 65217.5.1 Semantics of final Fields 65417.5.2 Reading final Fields During Construction 65417.5.3 Subsequent Modification of final Fields 65517.5.4 Write-Protected Fields 656

17.6 Word Tearing 65717.7 Non-Atomic Treatment of double and long 658

18 Type Inference 65918.1 Concepts and Notation 660

18.1.1 Inference Variables 66018.1.2 Constraint Formulas 66118.1.3 Bounds 661

18.2 Reduction 66318.2.1 Expression Compatibility Constraints 66318.2.2 Type Compatibility Constraints 66718.2.3 Subtyping Constraints 66818.2.4 Type Equality Constraints 67018.2.5 Checked Exception Constraints 671

18.3 Incorporation 67318.3.1 Complementary Pairs of Bounds 674

Page 20: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

The Java® Language Specification

xix

18.3.2 Bounds Involving Capture Conversion 67418.4 Resolution 67518.5 Uses of Inference 677

18.5.1 Invocation Applicability Inference 67818.5.2 Invocation Type Inference 67918.5.3 Functional Interface Parameterization Inference 68518.5.4 More Specific Method Inference 686

19 Syntax 689

Index 715

A Limited License Grant 755

Page 21: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

This page intentionally left blank

Page 22: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

xxi

Preface to the Java SE 8 Edition

IN 1996, James Gosling, Bill Joy, and Guy Steele wrote for the First Edition ofThe Java® Language Specification:

"We believe that the Java programming language is a mature language, ready forwidespread use. Nevertheless, we expect some evolution of the language in theyears to come. We intend to manage this evolution in a way that is completelycompatible with existing applications."

Java SE 8 represents the single largest evolution of the Java language in its history.A relatively small number of features - lambda expressions, method references, andfunctional interfaces - combine to offer a programming model that fuses the object-oriented and functional styles. Under the leadership of Brian Goetz, this fusionhas been accomplished in a way that encourages best practices - immutability,statelessness, compositionality - while preserving "the feel of Java" - readability,simplicity, universality.

Crucially, the libraries of the Java SE platform have co-evolved with the Javalanguage. This means that using lambda expressions and method references torepresent behavior - for example, an operation to be applied to each element ina list - is productive and performant "out of the box". In a similar fashion, theJava Virtual Machine has co-evolved with the Java language to ensure that defaultmethods support library evolution as consistently as possible across compile timeand run time, given the constraints of separate compilation.

Initiatives to add first-class functions to the Java language have been around sincethe 1990s. The BGGA and CICE proposals circa 2007 brought new energy tothe topic, while the creation of Project Lambda in OpenJDK circa 2009 attractedunprecedented levels of interest. The addition of method handles to the JVM inJava SE 7 opened the door to new implementation techniques while retaining"write once, run anywhere." In time, language changes were overseen by JSR 335,Lambda Expressions for the Java Programming Language, whose Expert Groupconsisted of Joshua Bloch, Kevin Bourrillion, Andrey Breslav, Rémi Forax, DanHeidinga, Doug Lea, Bob Lee, David Lloyd, Sam Pullara, Srikanth Sankaran, andVladimir Zakharov.

Programming language design typically involves grappling with degrees ofcomplexity utterly hidden from the language's users. (For this reason, it is oftencompared to an iceberg: 90% of it is invisible.) In JSR 335, the greatest complexity

Page 23: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

PREFACE TO THE JAVA SE 8 EDITION

xxii

lurked in the interaction of implicitly typed lambda expressions with overloadresolution. In this and many other areas, Dan Smith at Oracle did an outstanding jobof thoroughly specifying the desired behavior. His words are to be found throughoutthis specification, including an entirely new chapter on type inference.

Another initiative in Java SE 8 has been to enhance the utility of annotations, oneof the most popular features of the Java language. First, the Java grammar hasbeen extended to allow annotations on types in many language constructs, formingthe basis for novel static analysis tools such as the Checker Framework. Thisfeature was specified by JSR 308, Annotations on Java Types, led by Michael Ernstwith an Expert Group of myself, Doug Lea, and Srikanth Sankaran. The changesinvolved in this specification were wide-ranging, and the unstinting efforts ofMichael Ernst and Werner Dietl over many years are warmly recognized. Second,annotations may be "repeated" on a language construct, to the great benefit of APIsthat model domain-specific configuration with annotation types. Michael Keith andBill Shannon in Java EE initiated and guided this feature.

Many colleagues in the Java Platform Group at Oracle have provided valuablesupport to this specification: Leonid Arbouzov, Mandy Chung, Joe Darcy, RobertField, Joel Franck, Sonali Goel, Jon Gibbons, Jeannette Hung, Stuart Marks, EricMcCorkle, Matherey Nunez, Mark Reinhold, Vicente Romero, John Rose, GeorgesSaab, Steve Sides, Bernard Traversat, and Michel Trudeau.

Perhaps the greatest acknowledgement must go to the compiler engineers whoturn the specification into real software. Maurizio Cimadamore at Oracle workedheroically from the earliest days on the design of lambda expressions and theirimplementation in javac. Support for Java SE 8 features in Eclipse was contributedby Jayaprakash Arthanareeswaran, Shankha Banerjee, Anirban Chakraborty,Andrew Clement, Stephan Herrmann, Markus Keller, Jesper Møller, Manoj Palat,Srikanth Sankaran, and Olivier Thomann; and in IntelliJ by Anna Kozlova, AlexeyKudravtsev, and Roman Shevchenko. They deserve the thanks of the entire Javacommunity.

Java SE 8 is a renaissance for the Java language. While some search for the"next great language", we believe that programming in Java is more exciting andproductive than ever. We hope that it continues to wear well for you.

Alex BuckleySanta Clara, California

March, 2014

Page 24: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

1

C H A P T E R 1Introduction

THE Java® programming language is a general-purpose, concurrent, class-based, object-oriented language. It is designed to be simple enough that manyprogrammers can achieve fluency in the language. The Java programming languageis related to C and C++ but is organized rather differently, with a number of aspectsof C and C++ omitted and a few ideas from other languages included. It is intendedto be a production language, not a research language, and so, as C. A. R. Hoaresuggested in his classic paper on language design, the design has avoided includingnew and untested features.

The Java programming language is strongly and statically typed. This specificationclearly distinguishes between the compile-time errors that can and must be detectedat compile time, and those that occur at run time. Compile time normally consistsof translating programs into a machine-independent byte code representation.Run-time activities include loading and linking of the classes needed to executea program, optional machine code generation and dynamic optimization of theprogram, and actual program execution.

The Java programming language is a relatively high-level language, in that detailsof the machine representation are not available through the language. It includesautomatic storage management, typically using a garbage collector, to avoidthe safety problems of explicit deallocation (as in C's free or C++'s delete).High-performance garbage-collected implementations can have bounded pauses tosupport systems programming and real-time applications. The language does notinclude any unsafe constructs, such as array accesses without index checking, sincesuch unsafe constructs would cause a program to behave in an unspecified way.

The Java programming language is normally compiled to the bytecode instructionset and binary format defined in The Java Virtual Machine Specification, Java SE8 Edition.

Page 25: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

1 INTRODUCTION

2

1.1 Organization of the Specification

Chapter 2 describes grammars and the notation used to present the lexical andsyntactic grammars for the language.

Chapter 3 describes the lexical structure of the Java programming language, whichis based on C and C++. The language is written in the Unicode character set. Itsupports the writing of Unicode characters on systems that support only ASCII.

Chapter 4 describes types, values, and variables. Types are subdivided intoprimitive types and reference types.

The primitive types are defined to be the same on all machines and in allimplementations, and are various sizes of two's-complement integers, single- anddouble-precision IEEE 754 standard floating-point numbers, a boolean type, anda Unicode character char type. Values of the primitive types do not share state.

Reference types are the class types, the interface types, and the array types. Thereference types are implemented by dynamically created objects that are eitherinstances of classes or arrays. Many references to each object can exist. All objects(including arrays) support the methods of the class Object, which is the (single)root of the class hierarchy. A predefined String class supports Unicode characterstrings. Classes exist for wrapping primitive values inside of objects. In manycases, wrapping and unwrapping is performed automatically by the compiler (inwhich case, wrapping is called boxing, and unwrapping is called unboxing). Classand interface declarations may be generic, that is, they may be parameterized byother reference types. Such declarations may then be invoked with specific typearguments.

Variables are typed storage locations. A variable of a primitive type holds a valueof that exact primitive type. A variable of a class type can hold a null reference ora reference to an object whose type is that class type or any subclass of that classtype. A variable of an interface type can hold a null reference or a reference to aninstance of any class that implements the interface. A variable of an array type canhold a null reference or a reference to an array. A variable of class type Object canhold a null reference or a reference to any object, whether class instance or array.

Chapter 5 describes conversions and numeric promotions. Conversions change thecompile-time type and, sometimes, the value of an expression. These conversionsinclude the boxing and unboxing conversions between primitive types andreference types. Numeric promotions are used to convert the operands of a numericoperator to a common type where an operation can be performed. There are no

Page 26: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

Organization of the Specification 1.1

3

loopholes in the language; casts on reference types are checked at run time to ensuretype safety.

Chapter 6 describes declarations and names, and how to determine what namesmean (denote). The language does not require types or their members to be declaredbefore they are used. Declaration order is significant only for local variables, localclasses, and the order of initializers of fields in a class or interface.

The Java programming language provides control over the scope of namesand supports limitations on external access to members of packages, classes,and interfaces. This helps in writing large programs by distinguishing theimplementation of a type from its users and those who extend it. Recommendednaming conventions that make for more readable programs are described here.

Chapter 7 describes the structure of a program, which is organized into packagessimilar to the modules of Modula. The members of a package are classes, interfaces,and subpackages. Packages are divided into compilation units. Compilation unitscontain type declarations and can import types from other packages to give themshort names. Packages have names in a hierarchical name space, and the Internetdomain name system can usually be used to form unique package names.

Chapter 8 describes classes. The members of classes are classes, interfaces, fields(variables) and methods. Class variables exist once per class. Class methods operatewithout reference to a specific object. Instance variables are dynamically createdin objects that are instances of classes. Instance methods are invoked on instancesof classes; such instances become the current object this during their execution,supporting the object-oriented programming style.

Classes support single implementation inheritance, in which the implementationof each class is derived from that of a single superclass, and ultimately from theclass Object. Variables of a class type can reference an instance of that class or ofany subclass of that class, allowing new types to be used with existing methods,polymorphically.

Classes support concurrent programming with synchronized methods. Methodsdeclare the checked exceptions that can arise from their execution, which allowscompile-time checking to ensure that exceptional conditions are handled. Objectscan declare a finalize method that will be invoked before the objects are discardedby the garbage collector, allowing the objects to clean up their state.

For simplicity, the language has neither declaration "headers" separate from theimplementation of a class nor separate type and class hierarchies.

Page 27: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

1 INTRODUCTION

4

A special form of classes, enums, support the definition of small sets of values andtheir manipulation in a type safe manner. Unlike enumerations in other languages,enums are objects and may have their own methods.

Chapter 9 describes interface types, which declare a set of abstract methods,member types, and constants. Classes that are otherwise unrelated can implementthe same interface type. A variable of an interface type can contain a referenceto any object that implements the interface. Multiple interface inheritance issupported.

Annotation types are specialized interfaces used to annotate declarations. Suchannotations are not permitted to affect the semantics of programs in the Javaprogramming language in any way. However, they provide useful input to varioustools.

Chapter 10 describes arrays. Array accesses include bounds checking. Arrays aredynamically created objects and may be assigned to variables of type Object. Thelanguage supports arrays of arrays, rather than multidimensional arrays.

Chapter 11 describes exceptions, which are nonresuming and fully integrated withthe language semantics and concurrency mechanisms. There are three kinds ofexceptions: checked exceptions, run-time exceptions, and errors. The compilerensures that checked exceptions are properly handled by requiring that a methodor constructor can result in a checked exception only if the method or constructordeclares it. This provides compile-time checking that exception handlers exist, andaids programming in the large. Most user-defined exceptions should be checkedexceptions. Invalid operations in the program detected by the Java Virtual Machineresult in run-time exceptions, such as NullPointerException. Errors result fromfailures detected by the Java Virtual Machine, such as OutOfMemoryError. Mostsimple programs do not try to handle errors.

Chapter 12 describes activities that occur during execution of a program. A programis normally stored as binary files representing compiled classes and interfaces.These binary files can be loaded into a Java Virtual Machine, linked to other classesand interfaces, and initialized.

After initialization, class methods and class variables may be used. Some classesmay be instantiated to create new objects of the class type. Objects that are classinstances also contain an instance of each superclass of the class, and object creationinvolves recursive creation of these superclass instances.

When an object is no longer referenced, it may be reclaimed by the garbagecollector. If an object declares a finalizer, the finalizer is executed before the object

Page 28: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

Organization of the Specification 1.1

5

is reclaimed to give the object a last chance to clean up resources that would nototherwise be released. When a class is no longer needed, it may be unloaded.

Chapter 13 describes binary compatibility, specifying the impact of changes totypes on other types that use the changed types but have not been recompiled. Theseconsiderations are of interest to developers of types that are to be widely distributed,in a continuing series of versions, often through the Internet. Good programdevelopment environments automatically recompile dependent code whenever atype is changed, so most programmers need not be concerned about these details.

Chapter 14 describes blocks and statements, which are based on C and C++.The language has no goto statement, but includes labeled break and continuestatements. Unlike C, the Java programming language requires boolean (orBoolean) expressions in control-flow statements, and does not convert types toboolean implicitly (except through unboxing), in the hope of catching more errorsat compile time. A synchronized statement provides basic object-level monitorlocking. A try statement can include catch and finally clauses to protect againstnon-local control transfers.

Chapter 15 describes expressions. This document fully specifies the (apparent)order of evaluation of expressions, for increased determinism and portability.Overloaded methods and constructors are resolved at compile time by picking themost specific method or constructor from those which are applicable.

Chapter 16 describes the precise way in which the language ensures thatlocal variables are definitely set before use. While all other variables areautomatically initialized to a default value, the Java programming language doesnot automatically initialize local variables in order to avoid masking programmingerrors.

Chapter 17 describes the semantics of threads and locks, which are based onthe monitor-based concurrency originally introduced with the Mesa programminglanguage. The Java programming language specifies a memory model for shared-memory multiprocessors that supports high-performance implementations.

Chapter 18 describes a variety of type inference algorithms used to test applicabilityof generic methods and to infer types in a generic method invocation.

Chapter 19 presents a syntactic grammar for the language.

Page 29: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

1 INTRODUCTION

6

1.2 Example Programs

Most of the example programs given in the text are ready to be executed and aresimilar in form to:

class Test { public static void main(String[] args) { for (int i = 0; i < args.length; i++) System.out.print(i == 0 ? args[i] : " " + args[i]); System.out.println(); } }

On a machine with the Oracle JDK installed, this class, stored in the file Test.java,can be compiled and executed by giving the commands:

javac Test.javajava Test Hello, world.

producing the output:

Hello, world.

1.3 Notation

Throughout this specification we refer to classes and interfaces drawn from theJava SE platform API. Whenever we refer to a class or interface (other than thosedeclared in an example) using a single identifier N, the intended reference is to theclass or interface named N in the package java.lang. We use the canonical name(§6.7) for classes or interfaces from packages other than java.lang.

Non-normative information, designed to clarify the specification, is given insmaller, indented text.

This is non-normative information. It provides intuition, rationale, advice, examples, etc.

The type system of the Java programming language occasionally relies on thenotion of a substitution. The notation [F1:=T1,...,Fn:=Tn] denotes substitutionof Fi by Ti for 1 ≤ i ≤ n.

Page 30: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

Relationship to Predefined Classes and Interfaces 1.4

7

1.4 Relationship to Predefined Classes and Interfaces

As noted above, this specification often refers to classes of the Java SEplatform API. In particular, some classes have a special relationship withthe Java programming language. Examples include classes such as Object,Class, ClassLoader, String, Thread, and the classes and interfaces in packagejava.lang.reflect, among others. This specification constrains the behavior ofsuch classes and interfaces, but does not provide a complete specification for them.The reader is referred to the Java SE platform API documentation.

Consequently, this specification does not describe reflection in any detail.Many linguistic constructs have analogs in the Core Reflection API(java.lang.reflect) and the Language Model API (javax.lang.model), butthese are generally not discussed here. For example, when we list the ways in whichan object can be created, we generally do not include the ways in which the CoreReflection API can accomplish this. Readers should be aware of these additionalmechanisms even though they are not mentioned in the text.

1.5 Feedback

Readers may send feedback about errors, omissions, and ambiguities in The Java®

Language Specification to [email protected].

Questions concerning the behavior of javac (the reference compiler for the Javaprogramming language), and in particular its conformance to this specification,may be sent to [email protected].

1.6 References

Apple Computer. Dylan Reference Manual. Apple Computer Inc., Cupertino, California.September 29, 1995.

Bobrow, Daniel G., Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales,and David A. Moon. Common Lisp Object System Specification, X3J13 Document88-002R, June 1988; appears as Chapter 28 of Steele, Guy. Common Lisp: The Language,2nd ed. Digital Press, 1990, ISBN 1-55558-041-6, 770-864.

Ellis, Margaret A., and Bjarne Stroustrup. The Annotated C++ Reference Manual. Addison-Wesley, Reading, Massachusetts, 1990, reprinted with corrections October 1992, ISBN0-201-51459-1.

Page 31: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

1 INTRODUCTION

8

Goldberg, Adele and Robson, David. Smalltalk-80: The Language. Addison-Wesley, Reading,Massachusetts, 1989, ISBN 0-201-13688-0.

Harbison, Samuel. Modula-3. Prentice Hall, Englewood Cliffs, New Jersey, 1992, ISBN0-13-596396.

Hoare, C. A. R. Hints on Programming Language Design. Stanford University ComputerScience Department Technical Report No. CS-73-403, December 1973. Reprinted inSIGACT/SIGPLAN Symposium on Principles of Programming Languages. Associationfor Computing Machinery, New York, October 1973.

IEEE Standard for Binary Floating-Point Arithmetic. ANSI/IEEE Std. 754-1985. Availablefrom Global Engineering Documents, 15 Inverness Way East, Englewood, Colorado80112-5704 USA; 800-854-7179.

Kernighan, Brian W., and Dennis M. Ritchie. The C Programming Language, 2nd ed. PrenticeHall, Englewood Cliffs, New Jersey, 1988, ISBN 0-13-110362-8.

Madsen, Ole Lehrmann, Birger Møller-Pedersen, and Kristen Nygaard. Object-OrientedProgramming in the Beta Programming Language. Addison-Wesley, Reading,Massachusetts, 1993, ISBN 0-201-62430-3.

Mitchell, James G., William Maybury, and Richard Sweet. The Mesa Programming Language,Version 5.0. Xerox PARC, Palo Alto, California, CSL 79-3, April 1979.

Stroustrup, Bjarne. The C++ Progamming Language, 2nd ed. Addison-Wesley, Reading,Massachusetts, 1991, reprinted with corrections January 1994, ISBN 0-201-53992-6.

Unicode Consortium, The. The Unicode Standard, Version 6.0.0. Mountain View, CA, 2011,ISBN 978-1-936213-01-6.

Page 32: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

715

Index

Symbols= operator, 582

assignment contexts, 109expressions and run-time checks, 463, 464normal and abrupt completion of evaluation,465, 465

@Deprecated, 306@FunctionalInterface, 308@Inherited, 304@Override, 304@Repeatable, 308

repeatable annotation types, 298@Retention, 303

repeatable annotation types, 298@SafeVarargs, 307

formal parameters, 228@SuppressWarnings, 305

checked casts and unchecked casts, 121formal parameters, 228requirements in overriding and hiding, 246unchecked conversion, 103

@Target, 302multiple annotations of the same type, 318repeatable annotation types, 298where annotations may appear, 313

Aabrupt completion of do statement, 425

do statement, 425abrupt completion of for statement, 428

iteration of for statement, 428abrupt completion of while statement, 424

while statement, 423abstract classes, 192, 383

abstract methods, 232anonymous class declarations, 485array creation expressions, 487final classes, 194superinterfaces, 204

abstract interfaces, 279abstract methods, 232, 396

abstract classes, 192method body, 240method declarations, 286

access control, 161accessing superclass members using super,498class literals, 474class modifiers, 191constructor declarations, 256default constructor, 265enum body declarations, 269explicit constructor invocations, 262field access using a primary, 495identify potentially applicable methods, 509import declarations, 180interface modifiers, 278local class declarations, 407member type declarations, 254method declarations, 286normal annotations, 309objects, 54qualified expression names, 158, 158, 158

Page 33: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

716

qualified type names, 156, 156reference types and values, 53requirements in overriding and hiding, 247single-static-import declarations, 184single-type-import declarations, 181static-import-on-demand declarations, 184superclasses and subclasses, 200superinterfaces, 202superinterfaces and subinterfaces, 280type-import-on-demand declarations, 183

access to a protected member, 167access to members and constructors, 387accessing superclass members using super,497

declarations, 132field declarations, 213field initialization, 221, 222initialization of fields in interfaces, 285instance initializers, 255static methods, 234syntactic classification of a name accordingto context, 150

actions, 640synchronization order, 642

additive operators, 556constant expressions, 605integer operations, 43

additive operators (+ and -) for numeric types,559

binary numeric promotion, 126floating-point operations, 48

an array of characters is not a String, 339annotation type elements, 293

@Target, 303annotation types, 293declarations, 130, 131, 131marker annotations, 311normal annotations, 309

single-element annotations, 312syntactic classification of a name accordingto context, 150where types are used, 76

annotation types, 292@Target, 302annotations, 308declarations, 130interface declarations, 278

annotations, 308declarations, 132defaults for annotation type elements, 297syntactic classification of a name accordingto context, 150

anonymous class declarations, 485class instance creation expressions, 477, 477class modifiers, 191definite assignment and anonymous classes,627enum constants, 268form of a binary, 377initialization of fields in interfaces, 285inner classes and enclosing instances, 197syntactic classification of a name accordingto context, 151where types are used, 76, 77

anonymous constructors, 485choosing the constructor and its arguments,484default constructor, 265form of a binary, 381

argument lists are evaluated left-to-right, 470array access, 332array access expressions, 491

array access, 332assignment operators, 582compound assignment operators, 589simple assignment operator =, 582

Page 34: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

717

syntactic classification of a name accordingto context, 151unary numeric promotion, 125

array creation, 332array creation and access expressions, 487

method reference expressions, 529array creation expressions, 487

array creation, 332array initializers, 335objects, 53syntactic classification of a name accordingto context, 151unary numeric promotion, 125where types are used, 76, 78

array initializers, 335array creation, 332definite assignment and array initializers,626normal and abrupt completion of evaluation,464objects, 53run-time evaluation of array creationexpressions, 488

array members, 336declarations, 130, 130happens-before order, 644qualified expression names, 159

array store exception, 333array variables, 332assignment contexts, 109expressions and run-time checks, 463, 464normal and abrupt completion of evaluation,465variables, 80

array types, 330annotation type elements, 294enhanced for statement, 430raw types, 66

reference types and values, 52reifiable types, 65where types are used, 77

array variables, 330enhanced for statement, 431formal parameters, 228lambda parameters, 598

arrays, 329array creation expressions, 487kinds of variables, 83when reference types are the same, 57

assert statement, 416assert statements, 620detailed initialization procedure, 365when initialization occurs, 361

assert statements, 620assignment contexts, 107

array initializers, 335array store exception, 333array variables, 332class instance creation expressions, 478execution of try-catch, 444expressions and run-time checks, 463, 463kinds of types and values, 42lambda expressions, 595method invocation expressions, 500method reference expressions, 531normal annotations, 310reference conditional expressions, 580return statement, 436run-time evaluation of method references,540simple assignment operator =, 582, 583switch statement, 420throw statement, 437, 438type of an expression, 461variables, 80

assignment expressions, 615

Page 35: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

718

assignment operators, 581assignment contexts, 107assignment expressions, 615evaluation order for other expressions, 471field initialization, 221final variables, 86forms of expressions, 460initial values of variables, 87syntactic classification of a name accordingto context, 151variables, 80

asynchronous Exceptions, 343causes of Exceptions, 343

Bbasic for statement, 426

@Target, 303for statements, 622scope of a declaration, 140syntactic classification of a name accordingto context, 150where types are used, 76

basic try-with-resources, 448binary compatibility, 375binary numeric promotion, 125

additive operators (+ and -) for numeric types,559division operator /, 552integer bitwise operators &, ^, and |, 568multiplicative operators, 550numeric conditional expressions, 580numeric contexts, 124numerical comparison operators <, <=, >, and>=, 563numerical equality operators == and !=, 566postfix decrement operator --, 544postfix increment operator ++, 543

prefix decrement operator --, 547prefix increment operator ++, 546remainder operator %, 554shift operators, 561

bitwise and logical operators, 568constant expressions, 605

bitwise complement operator ~, 548constant expressions, 605integer operations, 43unary numeric promotion, 125

blocks, 407, 617blocks, 617kinds of variables, 84lambda body, 599local class declarations, 407scope of a declaration, 140

blocks and statements, 405boolean conditional expressions, 579boolean constant expressions, 613boolean equality operators == and !=, 567

boolean type and boolean values, 51boolean literals, 34

boolean type and boolean values, 51boxing conversion, 101constant expressions, 605identifiers, 23lexical literals, 473

boolean logical operators &, ^, and |, 569boolean type and boolean values, 51conditional-and operator &&, 570conditional-or operator ||, 570

boolean type and boolean values, 51boolean literals, 34lexical literals, 473

bounds, 661bounds involving capture conversion, 675invocation applicability inference, 678more specific method inference, 686

Page 36: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

719

reduction, 663bounds involving capture conversion, 674

incorporation, 673boxing conversion, 100

assignment contexts, 107casting contexts, 115class literals, 473conditional operator ? :, 579creation of new class instances, 366floating-point operations, 49integer operations, 44invocation contexts, 113invocation type inference, 680normal and abrupt completion of evaluation,465numeric conditional expressions, 579objects, 53postfix decrement operator --, 544postfix increment operator ++, 543prefix decrement operator --, 547prefix increment operator ++, 546type compatibility constraints, 668, 668

break statement, 432break, continue, return, and throw statements,624labeled statements, 413names and identifiers, 137normal and abrupt completion of statements,406

break, continue, return, and throwstatements, 624

Ccapture conversion, 103

array access expressions, 491assignment operators, 582bounds, 662

cast expressions, 549compile-time declaration of a methodreference, 533, 534compile-time step 3: is the chosen methodappropriate?, 520enhanced for statement, 430expression compatibility constraints, 667,667field access using a primary, 495function types, 325intersection types, 70least upper bound, 75members and constructors of parameterizedtypes, 63parameterized types, 59qualified expression names, 158, 158, 158,159, 159reference conditional expressions, 580resolution, 676simple expression names, 157subtyping among class and interface types,72type arguments of parameterized types, 61type of a method reference, 538

cast expressions, 549array types, 330casting contexts, 114compile-time step 3: is the chosen methodappropriate?, 519constant expressions, 605expressions and run-time checks, 463, 464floating-point operations, 48forms of expressions, 460happens-before order, 644integer operations, 43intersection types, 70normal and abrupt completion of evaluation,465

Page 37: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

720

objects, 54syntactic classification of a name accordingto context, 151type comparison operator instanceof, 564unary operators, 544where types are used, 76

casting contexts, 114boolean type and boolean values, 51cast expressions, 549, 550expressions and run-time checks, 463, 464happens-before order, 644kinds of types and values, 42lambda expressions, 595method reference expressions, 531objects, 54reference equality operators == and !=, 567

casting conversions to primitive types, 116casting conversions to reference types, 117causes of Exceptions, 343character literals, 34

boxing conversion, 101comments, 22constant expressions, 605escape sequences for character and Stringliterals, 37lexical literals, 473unicode, 16

check accessibility of type and method, 523run-time evaluation of method references,540, 540, 541

checked casts and unchecked casts, 121variables of reference type, 81

checked casts at run time, 122checked casts and unchecked casts, 122

checked exception constraints, 671choosing the constructor and its arguments,481

anonymous constructors, 486

class instance creation expressions, 478compile-time declaration of a methodreference, 533default constructor, 265expression compatibility constraints, 664formal parameters, 257

choosing the most specific method, 514compile-time declaration of a methodreference, 534, 535, 535compile-time step 2: determine methodSignature, 504conditional operator ? :, 572, 573method and constructor overloading, 399more specific method inference, 686, 686phase 1: identify matching arity methodsapplicable by strict invocation, 512phase 2: identify matching arity methodsapplicable by loose invocation, 513phase 3: identify methods applicable byvariable arity invocation, 513

class body and member declarations, 205, 386class members, 206member type declarations, 254, 254scope of a declaration, 140what binary compatibility is and is not, 382

class declarations, 191declarations, 130reference types and values, 52types, classes, and interfaces, 88

class instance creation expressions, 476conditional operator ? :, 572, 573constructor declarations, 256, 256constructor overloading, 264creation of new class instances, 365exception analysis of expressions, 346form of a binary, 379forms of expressions, 460functional interfaces, 319

Page 38: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

721

initial values of variables, 87, 87instance initializers, 255invocation contexts, 112invocation type inference, 681kinds of variables, 84method reference expressions, 529names and identifiers, 138objects, 53, 53return statement, 436run-time handling of an exception, 350String conversion, 106syntactic classification of a name accordingto context, 151, 151, 151types, classes, and interfaces, 88where types are used, 76, 76, 77, 77

class literals, 473declarations, 132normal annotations, 310syntactic classification of a name accordingto context, 150

class loading, 356causes of Exceptions, 343class literals, 474load the class test, 354

class members, 206abstract classes, 192declarations, 130function types, 323members and constructors of parameterizedtypes, 63method invocation type, 516

class modifiers, 191@Target, 302anonymous class declarations, 485local class declarations, 407reference type casting, 118, 118, 118

class Object, 55checked casts at run time, 122, 123

method invocation type, 517class objects for arrays, 338

types, classes, and interfaces, 88class String, 56

lexical literals, 473literals, 24objects, 53String literals, 35, 36

class type parameters, 385classes, 189

local class declarations, 407package members, 173qualified expression names, 158reclassification of contextually ambiguousnames, 153top level type declarations, 185

comments, 21input elements and tokens, 20lexical grammar, 9lexical translations, 16line terminators, 19unicode, 16

compilation units, 177determining accessibility, 162host support for packages, 175observability of a package, 179package members, 173reclassification of contextually ambiguousnames, 153, 153scope of a declaration, 139shadowing, 146syntactic grammar, 10

compile-time checking of Exceptions, 344checked exception constraints, 671

compile-time declaration of a methodreference, 532

checked exception constraints, 672choosing the most specific method, 515

Page 39: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

722

compile-time step 2: determine methodSignature, 503expression compatibility constraints, 666,667identify potentially applicable methods, 510invocation type inference, 683, 683method reference expressions, 531phase 1: identify matching arity methodsapplicable by strict invocation, 511run-time evaluation of method references,541

compile-time step 1: determine class orinterface to search, 500

class Object, 56compile-time declaration of a methodreference, 532identify potentially applicable methods, 509method invocation type, 517raw types, 68

compile-time step 2: determine methodSignature, 502

choosing the constructor and its arguments,483, 483compile-time declaration of a methodreference, 532enum constants, 268overloading, 251what binary compatibility is and is not, 382

compile-time step 3: is the chosen methodappropriate?, 517

check accessibility of type and method, 523choosing the most specific method, 515create frame, synchronize, transfer control,528form of a binary, 379locate method to invoke, 524, 524method invocation expressions, 499run-time evaluation of method references,540, 541, 542

complementary pairs of bounds, 674incorporation, 673

compound assignment operators, 588evaluate left-hand operand first, 466

compute target reference (if necessary), 520method reference expressions, 531

concepts and notation, 660conditional expression type (primitive 3rdoperand, part i), 574conditional expression type (primitive 3rdoperand, part ii), 575conditional expression type (reference 3rdoperand, part i), 576conditional expression type (reference 3rdoperand, part ii), 577conditional expression type (reference 3rdoperand, part iii), 578conditional operator ? :, 571, 614, 615

binary numeric promotion, 126boolean type and boolean values, 51, 51conditional operator ? :, 614, 615constant expressions, 605floating-point operations, 48forms of expressions, 460, 461identify potentially applicable methods, 511integer operations, 43objects, 55phase 1: identify matching arity methodsapplicable by strict invocation, 511

conditional-and operator &&, 570, 613boolean type and boolean values, 51conditional-and operator &&, 613constant expressions, 605

conditional-or operator ||, 570, 614boolean type and boolean values, 51conditional-or operator ||, 614constant expressions, 605forms of expressions, 460

Page 40: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

723

constant expressions, 605assignment contexts, 108boolean constant expressions, 613class String, 56creation of new class instances, 366final fields and static constant variables, 391final variables, 85forms of expressions, 461fp-strict expressions, 462initialization of fields in interfaces, 285normal annotations, 310numeric conditional expressions, 579objects, 53String concatenation operator +, 557String literals, 36subsequent modification of final fields, 655unreachable statements, 454, 454, 455

constraint formulas, 661reduction, 663

constructor body, 259constructor declarations, 256definite assignment, constructors, andinstance initializers, 629initial values of variables, 87kinds of variables, 84return statement, 436this, 474

constructor declarations, 256class body and member declarations, 206creation of new class instances, 366declarations, 131, 131final fields, 219raw types, 67return statement, 436run-time evaluation of class instance creationexpressions, 484simple expression names, 157

syntactic classification of a name accordingto context, 150where types are used, 77

constructor modifiers, 258@Target, 303

constructor overloading, 264constructor Signature, 258

form of a binary, 380constructor throws, 259

compile-time checking of Exceptions, 344declarations, 132syntactic classification of a name accordingto context, 150throw statement, 438where types are used, 76, 78

context-free grammars, 9compilation units, 177

continue statement, 434break, continue, return, and throw statements,624labeled statements, 413names and identifiers, 137normal and abrupt completion of statements,406

conversions and contexts, 91parenthesized expressions, 476type of an expression, 461

create frame, synchronize, transfer control,528

run-time evaluation of method references,540, 540, 541

creation of new class instances, 365constructor declarations, 256field initialization, 222form of a binary, 377instance initializers, 255run-time evaluation of class instance creationexpressions, 484

Page 41: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

724

static fields, 216String concatenation operator +, 557when initialization occurs, 361

Ddeclarations, 130

functional interfaces, 322members and constructors of parameterizedtypes, 64names and identifiers, 137syntactic classification of a name accordingto context, 150where types are used, 77, 78

default constructor, 265form of a binary, 381method and constructor declarations, 394

defaults for annotation type elements, 297marker annotations, 312single-element annotations, 312syntactic classification of a name accordingto context, 152

definite assignment, 607assignment operators, 582final variables, 85, 85, 86initial values of variables, 87inner classes and enclosing instances, 199kinds of variables, 84lambda body, 600parenthesized expressions, 476

definite assignment and anonymous classes,627definite assignment and array initializers, 626definite assignment and enum constants, 626definite assignment and expressions, 613definite assignment and member types, 627definite assignment and parameters, 626definite assignment and statements, 617

definite assignment and static initializers, 628definite assignment and enum constants, 626final fields, 219

definite assignment, constructors, andinstance initializers, 628

final fields, 219detailed initialization procedure, 363

field initialization, 221, 221final fields and static constant variables, 393form of a binary, 377initialization of fields in interfaces, 285simple expression names, 157static initializers, 255throw statement, 439when initialization occurs, 361

details on protected access, 166determining accessibility, 163

determining accessibility, 162top level type declarations, 185

determining enclosing instances, 480anonymous constructors, 486choosing the constructor and its arguments,482, 482class instance creation expressions, 478compile-time declaration of a methodreference, 535default constructor, 265formal parameters, 257inner classes and enclosing instances, 198method reference expressions, 531run-time evaluation of method references,541

determining the class being instantiated, 478abstract classes, 192class instance creation expressions, 478enum types, 267

determining the meaning of a name, 148class members, 207

Page 42: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

725

declarations, 131interface members, 283names and identifiers, 137obscuring, 147where types are used, 77

division operator /, 552compound assignment operators, 590evaluate operands before operation, 468integer operations, 44normal and abrupt completion of evaluation,465

do statement, 424boolean type and boolean values, 51do statements, 622

do statements, 622

Eempty statement, 412

empty statements, 617empty statements, 617enhanced for statement, 429

@Target, 303array variables, 331for statements, 622scope of a declaration, 141syntactic classification of a name accordingto context, 150where types are used, 76

enum body declarations, 268constructor declarations, 256declarations, 130, 130, 131

enum constants, 267@Target, 303definite assignment and enum constants, 626definite assignment and static initializers,628enum types, 267

normal annotations, 310where types are used, 76

enum members, 271declarations, 130form of a binary, 381

enum types, 266@Target, 302abstract methods, 232class declarations, 191declarations, 130normal annotations, 310superclasses and subclasses, 200switch statement, 420

equality operators, 565constant expressions, 605

erasure, 64assignment contexts, 109cast expressions, 549checked casts and unchecked casts, 122checked casts at run time, 122choosing the most specific method, 516class type parameters, 385compile-time step 3: is the chosen methodappropriate?, 519constructor Signature, 258create frame, synchronize, transfer control,528declarations, 131evaluate arguments, 522field declarations, 390form of a binary, 378, 379, 380invocation contexts, 114method and constructor formal parameters,396method and constructor type parameters, 395method result type, 396method Signature, 230raw types, 66

Page 43: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

726

requirements in overriding and hiding, 246type variables, 58

escape sequences for character and Stringliterals, 37

character literals, 34String literals, 35

evaluate arguments, 522formal parameters, 229variables of reference type, 81

evaluate left-hand operand first, 466evaluate operands before operation, 468evaluation order, 466evaluation order for other expressions, 471evaluation respects parentheses andprecedence, 469evaluation, denotation, and result, 459

assert statement, 417evolution of annotation types, 403evolution of classes, 383evolution of enums, 400evolution of interfaces, 400evolution of packages, 383example programs, 6exception analysis of expressions, 346

class instance creation expressions, 477compile-time checking of Exceptions, 345method invocation expressions, 499

exception analysis of statements, 346compile-time checking of Exceptions, 345explicit constructor invocations, 262method throws, 238throw statement, 438try statement, 443

exception checking, 347compile-time checking of Exceptions, 344field initialization, 222instance initializers, 255method throws, 239

static initializers, 256throw statement, 439, 439try statement, 443type of a lambda expression, 603

Exceptions, 341floating-point operations, 49integer operations, 44normal and abrupt completion of statements,406throw statement, 437

execution, 353execution of local variable declarations, 410execution of try-catch, 444

try statement, 443execution of try-finally and try-catch-finally,445

try statement, 443executions, 646

well-formed executions, 647executions and causality requirements, 647explicit constructor invocations, 260

anonymous constructors, 486, 486constructor body, 259creation of new class instances, 366definite assignment, constructors, andinstance initializers, 629, 629enum body declarations, 269exception analysis of statements, 347form of a binary, 379inner classes and enclosing instances, 197,198instance initializers, 255invocation contexts, 112syntactic classification of a name accordingto context, 151, 151where types are used, 76, 77

expression compatibility constraints, 663expression names, 543

Page 44: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

727

declarations, 132expression statements, 414, 620

evaluation, denotation, and result, 459expression statements, 620identify potentially applicable methods, 510initialization of for statement, 427

expressions, 459expressions and run-time checks, 462extended try-with-resources, 451

Ffeedback, 7field (constant) declarations, 283

@Target, 303array initializers, 335array variables, 330, 331declarations, 130final variables, 85interface body and member declarations, 282kinds of variables, 83obscuring, 147shadowing, 144syntactic classification of a name accordingto context, 150where types are used, 76

field access expressions, 494assignment operators, 582names and identifiers, 138normal and abrupt completion of evaluation,465objects, 54raw types, 68simple assignment operator =, 582static initializers, 256

field access using a primary, 494field declarations, 211, 388, 402

array initializers, 335

array variables, 330, 331class body and member declarations, 205creation of new class instances, 366declarations, 130field declarations, 402obscuring, 147raw types, 67reclassification of contextually ambiguousnames, 152shadowing, 144simple expression names, 157syntactic classification of a name accordingto context, 150where annotations may appear, 314where types are used, 76

field initialization, 221definite assignment and static initializers,628definite assignment, constructors, andinstance initializers, 628detailed initialization procedure, 364exception checking, 347, 348final fields and static constant variables, 393initialization of fields in interfaces, 285simple expression names, 157static initializers, 255this, 474

field modifiers, 215@Target, 303field declarations, 212

final classes, 194, 383anonymous class declarations, 485final methods, 234superclasses and subclasses, 200verification of the binary representation, 359

final field semantics, 652memory model, 639

final fields, 219

Page 45: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

728

final fields and static constant variables, 391field declarations, 402final variables, 85verification of the binary representation, 359

final methods, 234, 397verification of the binary representation, 359

final variables, 85constant expressions, 606, 606detailed initialization procedure, 364enum body declarations, 269field initialization, 221final fields, 219final fields and static constant variables, 391form of a binary, 377initialization of fields in interfaces, 285inner classes and enclosing instances, 197,199, 199lambda body, 600local variable declarators and types, 410narrowing reference conversion, 99try statement, 442try-with-resources, 448when initialization occurs, 361

finalization of class instances, 369class Object, 56enum body declarations, 269happens-before order, 643kinds of variables, 83unloading of classes and interfaces, 373

floating-point literals, 31constant expressions, 605lexical literals, 473

floating-point operations, 48additive operators (+ and -) for numeric types,561division operator /, 553multiplication operator *, 552narrowing primitive conversion, 96

widening primitive conversion, 95floating-point types, formats, and values, 45

cast expressions, 550field declarations, 213floating-point literals, 33formal parameters, 229fp-strict expressions, 462lambda parameters, 598lexical literals, 473, 473local variable declarators and types, 410narrowing primitive conversion, 97, 97parenthesized expressions, 476return statement, 437unary minus operator -, 548

floating-point value set parameters, 46floating-point types, formats, and values, 46,46, 46

for statement, 426boolean type and boolean values, 51declarations, 131initial values of variables, 87kinds of variables, 84local variable declaration statements, 409

for statements, 622forbidden conversions, 106form of a binary, 376

check accessibility of type and method, 523compile-time step 3: is the chosen methodappropriate?, 519final variables, 85loading of classes and interfaces, 356locate method to invoke, 524resolution of symbolic references, 359top level type declarations, 187when reference types are the same, 56, 57

formal parameters, 226, 257@Target, 303array variables, 331

Page 46: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

729

choosing the constructor and its arguments,482compile-time declaration of a methodreference, 537compile-time step 3: is the chosen methodappropriate?, 519declarations, 131, 131default constructor, 265definite assignment and parameters, 626,626evaluate arguments, 522form of a binary, 381formal parameters, 257initial values of variables, 87, 87invoke test.main, 356kinds of variables, 83, 84lambda parameters, 597, 598method and constructor formal parameters,395method declarations, 226reclassification of contextually ambiguousnames, 152, 152scope of a declaration, 140, 140shadowing and obscuring, 142shared variables, 640syntactic classification of a name accordingto context, 150, 150, 150this, 474variables of reference type, 81where types are used, 76, 76, 76, 77

forms of expressions, 460boolean conditional expressions, 579choosing the most specific method, 515class instance creation expressions, 478conditional operator ? :, 572, 572expression compatibility constraints, 663,663identify potentially applicable methods, 511

lambda expressions, 594method reference expressions, 531more specific method inference, 687numeric conditional expressions, 579parenthesized expressions, 476

forward references during field initialization,222

when initialization occurs, 361fp-strict expressions, 462

additive operators (+ and -) for numeric types,560cast expressions, 550constant expressions, 606division operator /, 553floating-point types, formats, and values, 45formal parameters, 229method declarations, 286multiplication operator *, 551return statement, 437strictfp classes, 194strictfp interfaces, 279strictfp methods, 235value set conversion, 106, 107widening primitive conversion, 95

fully qualified names and canonical names,169

compilation units, 177form of a binary, 377, 380import declarations, 180, 180local class declarations, 407named packages, 178notation, 6package members, 174single-static-import declarations, 184single-type-import declarations, 181static-import-on-demand declarations, 184top level type declarations, 185type-import-on-demand declarations, 183

Page 47: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

730

function types, 323checked exception constraints, 672expression compatibility constraints, 666type of a lambda expression, 602type of a method reference, 538

functional interface parameterizationinference, 685

expression compatibility constraints, 664type of a lambda expression, 602

functional interfaces, 319@FunctionalInterface, 308checked exception constraints, 671expression compatibility constraints, 664functional interface parameterizationinference, 685identify potentially applicable methods, 510lambda expressions, 595method reference expressions, 531type of a lambda expression, 602type of a method reference, 537

Ggeneric classes and type parameters, 194

@Target, 303capture conversion, 103class instance creation expressions, 477declarations, 130form of a binary, 377generic constructors, 259generic methods, 237parameterized types, 59scope of a declaration, 140syntactic classification of a name accordingto context, 150type variables, 57types, classes, and interfaces, 89where types are used, 76

generic constructors, 259@Target, 303class instance creation expressions, 477declarations, 130form of a binary, 377scope of a declaration, 140syntactic classification of a name accordingto context, 150type erasure, 64type variables, 57where types are used, 76

generic interfaces and type parameters, 279@Target, 303capture conversion, 103declarations, 130form of a binary, 377parameterized types, 59scope of a declaration, 140subtyping among class and interface types,72superinterfaces, 203syntactic classification of a name accordingto context, 150type variables, 57types, classes, and interfaces, 89where types are used, 76

generic methods, 237@Target, 303compile-time declaration of a methodreference, 537compile-time step 2: determine methodSignature, 504declarations, 130form of a binary, 377function types, 323, 323method declarations, 226, 287method invocation expressions, 500method result, 238

Page 48: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

731

method Signature, 230scope of a declaration, 140syntactic classification of a name accordingto context, 150type erasure, 64type variables, 57where types are used, 76

grammar notation, 10grammars, 9

Hhappens-before order, 643

executions, 646executions and causality requirements, 649finalization of class instances, 370

hiding (by class methods), 245obscuring, 147shadowing, 144

host support for packages, 175top level type declarations, 187

Iidentifiers, 22

declarations, 130keywords, 24lexical grammar, 9

identify potentially applicable methods, 509compile-time declaration of a methodreference, 533, 533, 534compile-time step 1: determine class orinterface to search, 500compile-time step 2: determine methodSignature, 503phase 1: identify matching arity methodsapplicable by strict invocation, 511

phase 2: identify matching arity methodsapplicable by loose invocation, 512phase 3: identify methods applicable byvariable arity invocation, 513

identity conversion, 94assignment contexts, 107boxing conversion, 101capture conversion, 104casting contexts, 115invocation contexts, 112, 113numeric contexts, 124unary numeric promotion, 124

if statement, 415boolean type and boolean values, 51

if statements, 620if-then statement, 415

if statements, 620if-then-else statement, 416

if statements, 620implementing finalization, 370import declarations, 180

compilation units, 177incorporation, 673incrementation part of for statement, 623inference variables, 660inheritance and overriding, 287

compile-time checking of Exceptions, 345compile-time declaration of a methodreference, 535compile-time step 3: is the chosen methodappropriate?, 518interface members, 283method declarations, 287

inheritance, overriding, and hiding, 240class Object, 56compile-time declaration of a methodreference, 535enum constants, 268

Page 49: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

732

function types, 323inheriting methods with override-equivalentsignatures, 250, 289

variables of reference type, 81initial values of variables, 87

array initializers, 335creation of new class instances, 366field initialization, 221final fields and static constant variables, 393initialization of fields in interfaces, 285kinds of variables, 83, 83, 83preparation of a class or interface type, 359run-time evaluation of array creationexpressions, 488run-time evaluation of class instance creationexpressions, 484variables, 80

initialization of classes and interfaces, 360causes of Exceptions, 343initialize test: execute initializers, 356objects, 53preparation of a class or interface type, 359run-time handling of an exception, 350static fields, 216

initialization of fields in interfaces, 285detailed initialization procedure, 364field initialization, 221final fields and static constant variables, 393

initialization of for statement, 427initialization part of for statement, 623initialize test: execute initializers, 355inner classes and enclosing instances, 197

anonymous class declarations, 485compile-time step 3: is the chosen methodappropriate?, 517determining enclosing instances, 480explicit constructor invocations, 261form of a binary, 381

local class declarations, 407method reference expressions, 531qualified this, 475when initialization occurs, 361

input elements and tokens, 19invocation type inference, 681lexical grammar, 9, 9lexical translations, 16unicode, 16

instance creation, 365, 476conditional operator ? :, 572, 573constructor declarations, 256, 256, 256constructor overloading, 264creation of new class instances, 365exception analysis of expressions, 346field initialization, 222form of a binary, 377, 379forms of expressions, 460functional interfaces, 319initial values of variables, 87, 87instance initializers, 255, 255invocation contexts, 112invocation type inference, 681kinds of variables, 84method reference expressions, 529names and identifiers, 138objects, 53, 53return statement, 436run-time evaluation of class instance creationexpressions, 484run-time handling of an exception, 350static fields, 216String concatenation operator +, 557String conversion, 106syntactic classification of a name accordingto context, 151, 151, 151types, classes, and interfaces, 88when initialization occurs, 361

Page 50: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

733

where types are used, 76, 76, 77, 77instance initializers, 255

class body and member declarations, 206definite assignment, constructors, andinstance initializers, 629exception checking, 348return statement, 436simple expression names, 157this, 474throw statement, 439

instanceof operator, 564expressions and run-time checks, 463objects, 54syntactic classification of a name accordingto context, 151where types are used, 76, 78

integer bitwise operators &, ^, and |, 568binary numeric promotion, 126integer operations, 43shift operators, 562, 562

integer literals, 25boxing conversion, 101constant expressions, 605lexical literals, 473

integer operations, 43integral types and values, 43

character literals, 34integer literals, 25lexical literals, 473, 473, 473

interaction with the memory model, 372interactions of waits, notification, andinterruption, 635interface body and member declarations, 282

interface members, 282member type declarations, 254, 254scope of a declaration, 140

interface declarations, 278declarations, 130

reference types and values, 52types, classes, and interfaces, 88

interface members, 282, 401check accessibility of type and method, 523declarations, 130form of a binary, 378, 380

interface method body, 291superinterfaces, 204this, 474

interface method declarations, 402interface methods, 286

@Target, 303, 303array variables, 331declarations, 131, 131, 132inheritance, overriding, and hiding, 241interface body and member declarations, 282raw types, 67syntactic classification of a name accordingto context, 150, 150, 150where types are used, 76, 76, 76, 78

interface modifiers, 278@Target, 302static member type declarations, 255

interface type parameters, 401interfaces, 277

package members, 173qualified expression names, 158reclassification of contextually ambiguousnames, 153top level type declarations, 185

interruptions, 635intersection types, 70

form of a binary, 378, 379functional interfaces, 323type variables, 58where types are used, 77

introduction, 1invocation applicability inference, 678

Page 51: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

734

invocation type inference, 679, 680, 680,682phase 1: identify matching arity methodsapplicable by strict invocation, 512phase 2: identify matching arity methodsapplicable by loose invocation, 512phase 3: identify methods applicable byvariable arity invocation, 513

invocation contexts, 112class instance creation expressions, 478constraint formulas, 661, 661create frame, synchronize, transfer control,528expression compatibility constraints, 663formal parameters, 229kinds of types and values, 42lambda expressions, 595method invocation expressions, 500method reference expressions, 531reference conditional expressions, 580type compatibility constraints, 668

invocation type inference, 679expression compatibility constraints, 664,667invocation type inference, 681method invocation type, 516

invoke test.main, 356iteration of for statement, 427

JJava Virtual Machine startup, 353

Kkeywords, 24

identifiers, 23lexical grammar, 9

primitive types and values, 42kinds and causes of Exceptions, 342kinds of conversion, 94kinds of Exceptions, 342

compile-time checking of Exceptions, 345,345generic classes and type parameters, 195method throws, 238, 239narrowing primitive conversion, 97throw statement, 438widening primitive conversion, 95

kinds of types and values, 41capture conversion, 103lexical literals, 473literals, 24null literal, 38throw statement, 438

kinds of variables, 83formal parameters, 227

Llabeled statements, 413, 619

break statement, 432continue statement, 434labeled statements, 619names and identifiers, 137

lambda body, 599choosing the most specific method, 515identify potentially applicable methods, 510,510kinds of variables, 84type of a lambda expression, 603

lambda expressions, 594exception analysis of expressions, 346forms of expressions, 460, 461functional interfaces, 319identify potentially applicable methods, 510

Page 52: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

735

return statement, 436scope of a declaration, 140

lambda parameters, 596array variables, 331choosing the most specific method, 514, 514compile-time step 2: determine methodSignature, 503declarations, 131kinds of variables, 84phase 1: identify matching arity methodsapplicable by strict invocation, 511shadowing and obscuring, 142syntactic classification of a name accordingto context, 150where types are used, 76

least upper bound, 73intersection types, 70resolution, 676

lexical grammar, 9lexical literals, 472

kinds of types and values, 42lexical structure, 15

lexical grammar, 9lexical translations, 16line terminators, 19

character literals, 34input elements and tokens, 19lexical translations, 16white space, 20

link test: verify, prepare, (optionally) resolve,354linking of classes and interfaces, 358

causes of Exceptions, 343check accessibility of type and method, 523link test: verify, prepare, (optionally) resolve,354resolution of symbolic references, 360

literals, 24

lexical grammar, 9lexical literals, 472

load the class test, 354loading of classes and interfaces, 356

causes of Exceptions, 343class literals, 474load the class test, 354

loading process, 357superclasses and subclasses, 202superinterfaces and subinterfaces, 281

local class declaration statements, 619local class declarations, 407

class instance creation expressions, 477class modifiers, 191form of a binary, 377inner classes and enclosing instances, 197local class declaration statements, 619reclassification of contextually ambiguousnames, 153shadowing and obscuring, 142

local variable declaration statements, 408,619

@Target, 303array initializers, 335declarations, 131initial values of variables, 87initialization of for statement, 427initialization part of for statement, 623kinds of variables, 84local variable declaration statements, 619objects, 53reclassification of contextually ambiguousnames, 152scope of a declaration, 140shadowing and obscuring, 142shared variables, 640syntactic classification of a name accordingto context, 150

Page 53: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

736

where types are used, 76local variable declarators and types, 409

array variables, 330, 331locate method to invoke, 524

run-time evaluation of method references,540, 540, 541

logical complement operator !, 548, 614boolean type and boolean values, 51constant expressions, 605logical complement operator !, 614

Mmarker annotations, 311

annotations, 308meaning of expression names, 156

expression names, 543forms of expressions, 460names and identifiers, 137

meaning of method names, 160names and identifiers, 137

meaning of package names, 154names and identifiers, 137

meaning of packageortypenames, 155type-import-on-demand declarations, 183

meaning of type names, 155names and identifiers, 137

member type declarations, 254, 291@Target, 302, 302class body and member declarations, 205class instance creation expressions, 477, 477class modifiers, 191, 191declarations, 130, 130, 130, 130definite assignment and member types, 627,627form of a binary, 377, 377, 381, 381inner classes and enclosing instances, 197,197

interface body and member declarations, 282interface modifiers, 279member type declarations, 291obscuring, 147, 147qualified type names, 156, 156reclassification of contextually ambiguousnames, 153, 153, 154, 154reference types and values, 53, 53shadowing, 144, 144static-import-on-demand declarations, 185,185syntactic classification of a name accordingto context, 150, 150type-import-on-demand declarations, 183,183where types are used, 76, 76, 76, 76

members and constructors of parameterizedtypes, 63memory model, 637

interaction with the memory model, 372volatile fields, 220

method and constructor body, 398method and constructor declarations, 394

method and constructor formal parameters,395method result type, 396

method and constructor formal parameters,395

interface method declarations, 402method and constructor overloading, 399

interface method declarations, 402method and constructor throws, 398

interface method declarations, 402method and constructor type parameters, 394

class type parameters, 385method body, 240

abstract methods, 232constructor body, 260

Page 54: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

737

method declarations, 226native methods, 235this, 474

method declarations, 225, 286@Target, 303, 303array variables, 331class body and member declarations, 205declarations, 130, 131, 131, 132evaluation, denotation, and result, 459inheritance, overriding, and hiding, 241interface body and member declarations, 282raw types, 67, 67return statement, 436simple expression names, 157syntactic classification of a name accordingto context, 150, 150, 150, 150where types are used, 76, 76, 76, 78

method invocation expressions, 499anonymous constructors, 486, 486compile-time declaration of a methodreference, 532conditional operator ? :, 572, 573constructor declarations, 257declarations, 132evaluation, denotation, and result, 459exception analysis of expressions, 346expressions and run-time checks, 463field initialization, 221, 222formal parameters, 229forms of expressions, 461happens-before order, 644hiding (by class methods), 245initial values of variables, 87initialization of fields in interfaces, 285instance initializers, 255invocation contexts, 112invocation type inference, 681kinds of variables, 83, 84

lambda parameters, 598method declarations, 226names and identifiers, 138normal and abrupt completion of evaluation,465, 465objects, 54overloading, 251overriding (by instance methods), 242return statement, 436run-time handling of an exception, 350simple method names, 160static initializers, 256syntactic classification of a name accordingto context, 150, 151, 152this, 474where types are used, 76, 77

method invocation type, 516choosing the constructor and its arguments,483, 483compile-time declaration of a methodreference, 537compile-time step 3: is the chosen methodappropriate?, 518exception analysis of expressions, 346, 346exception analysis of statements, 347expression compatibility constraints, 667invocation type inference, 679type compatibility constraints, 668type of a method reference, 538

method modifiers, 231@Target, 303method declarations, 226objects, 55

method overriding, 400method reference expressions, 529

access to a protected member, 167declarations, 132expressions and run-time checks, 463, 464

Page 55: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

738

form of a binary, 379forms of expressions, 460, 461functional interfaces, 319identify potentially applicable methods, 510names and identifiers, 138syntactic classification of a name accordingto context, 150, 151, 152where types are used, 76, 77, 77

method result, 237abstract classes, 192abstract methods, 232class literals, 473constructor declarations, 256function types, 323functional interfaces, 319interface method body, 291method body, 240method declarations, 226requirements in overriding and hiding, 246return statement, 436type erasure, 64where types are used, 76

method result type, 396interface method declarations, 402

method Signature, 230abstract classes, 192abstract methods, 232choosing the most specific method, 516constructor Signature, 258form of a binary, 379functional interfaces, 319hiding (by class methods), 245inheritance and overriding, 287inheritance, overriding, and hiding, 241, 241inheriting methods with override-equivalentsignatures, 250, 289interface members, 282method declarations, 226, 287

method result, 238overloading, 290overriding (by instance methods), 241, 242,288requirements in overriding and hiding, 246type erasure, 64

method throws, 238abstract methods, 232compile-time checking of Exceptions, 344constructor throws, 259declarations, 132method declarations, 226syntactic classification of a name accordingto context, 150throw statement, 438where types are used, 76, 78

more specific method inference, 686choosing the most specific method, 514

multiple annotations of the same type, 318annotation types, 292annotations, 308class modifiers, 191constructor modifiers, 258enum constants, 268field (constant) declarations, 283field modifiers, 215formal parameters, 228generic classes and type parameters, 195generic interfaces and type parameters, 280interface modifiers, 278lambda parameters, 598local variable declaration statements, 409method declarations, 286method modifiers, 231named packages, 178

multiplication operator *, 551multiplicative operators, 550

binary numeric promotion, 126

Page 56: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

739

constant expressions, 605floating-point operations, 48forms of expressions, 460integer operations, 43

Nname classification, 149

access control, 161declarations, 132reference types and values, 53

name reclassification, 152method invocation expressions, 499

named packages, 178@Target, 302

names, 129names and identifiers, 137

compile-time declaration of a methodreference, 535import declarations, 180local class declarations, 407named packages, 178shadowing and obscuring, 142

narrowing primitive conversion, 96casting contexts, 115floating-point operations, 49narrowing primitive conversion, 97postfix decrement operator --, 544postfix increment operator ++, 543prefix decrement operator --, 547prefix increment operator ++, 546widening and narrowing primitiveconversion, 99

narrowing reference conversion, 99casting contexts, 115

native methods, 235, 397method body, 240

new keyword, 476

conditional operator ? :, 572, 573constructor declarations, 256, 256constructor overloading, 264creation of new class instances, 365exception analysis of expressions, 346form of a binary, 379forms of expressions, 460functional interfaces, 319initial values of variables, 87, 87instance initializers, 255invocation contexts, 112invocation type inference, 681kinds of variables, 84method reference expressions, 529names and identifiers, 138objects, 53, 53return statement, 436run-time handling of an exception, 350String conversion, 106syntactic classification of a name accordingto context, 151, 151, 151types, classes, and interfaces, 88where types are used, 76, 76, 77, 77

non-atomic treatment of double and long, 658normal and abrupt completion of evaluation,464

causes of Exceptions, 343normal and abrupt completion of statements,406, 406run-time handling of an exception, 350

normal and abrupt completion of statements,405

interface method body, 291method body, 240normal and abrupt completion of evaluation,466run-time handling of an exception, 350

normal annotations, 309

Page 57: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

740

annotations, 308defaults for annotation type elements, 297names and identifiers, 138syntactic classification of a name accordingto context, 152

notation, 6notification, 634null literal, 38

compile-time step 3: is the chosen methodappropriate?, 518identifiers, 23kinds of types and values, 42lexical literals, 473

numeric conditional expressions, 579numeric contexts, 124

floating-point operations, 48integer operations, 44

numerical comparison operators <, <=, >, and>=, 563

binary numeric promotion, 126floating-point operations, 48floating-point types, formats, and values, 47integer operations, 43

numerical equality operators == and !=, 566binary numeric promotion, 126floating-point operations, 48floating-point types, formats, and values, 47integer operations, 43

Oobject creation, 365

constructor declarations, 256field initialization, 222form of a binary, 377instance initializers, 255run-time evaluation of class instance creationexpressions, 484

static fields, 216String concatenation operator +, 557when initialization occurs, 361

objects, 53, 55checked casts at run time, 122, 123method invocation type, 517String literals, 36

obscuring, 147labeled statements, 413shadowing, 144

observability of a package, 179qualified package names, 155scope of a declaration, 139

observable behavior and nonterminatingexecutions, 650

actions, 640, 641operators, 38

input elements and tokens, 20lexical grammar, 9

operators ++ and --, 616organization of the specification, 2other expressions, 616other expressions of type boolean, 615overload resolution, 502, 509, 511, 512, 513,514

choosing the constructor and its arguments,483, 483, 483choosing the most specific method, 514compile-time declaration of a methodreference, 532, 533, 533, 534, 534, 534,534, 534, 534, 534, 534, 534, 535, 535,535, 535compile-time step 1: determine class orinterface to search, 500compile-time step 2: determine methodSignature, 503, 503, 503, 503, 503, 503,503, 504conditional operator ? :, 572, 573

Page 58: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

741

enum constants, 268invocation applicability inference, 678, 678invocation type inference, 680method and constructor overloading, 399more specific method inference, 686, 686,686, 686, 686overloading, 251phase 1: identify matching arity methodsapplicable by strict invocation, 511, 512,512phase 2: identify matching arity methodsapplicable by loose invocation, 512, 512,513, 513phase 3: identify methods applicable byvariable arity invocation, 513, 513, 513, 513what binary compatibility is and is not, 382

overloading, 250, 290constructor overloading, 264

overriding (by instance methods), 241, 288final classes, 194locate method to invoke, 525superinterfaces, 204

Ppackage declarations, 178

compilation units, 177declarations, 130

package members, 173packages, 173parameterized types, 59

annotation type elements, 294capture conversion, 103, 104checked casts and unchecked casts, 121class literals, 474declarations, 131determining the class being instantiated, 478field declarations, 390

functional interfaces, 323generic classes and type parameters, 195generic interfaces and type parameters, 280method and constructor formal parameters,396method reference expressions, 530method result type, 396normal annotations, 310raw types, 66reference type casting, 117reference types and values, 52superclasses and subclasses, 200superinterfaces, 202superinterfaces and subinterfaces, 281type erasure, 64types, classes, and interfaces, 89where types are used, 77

parenthesized expressions, 475conditional operator ? :, 572, 572constant expressions, 606forms of expressions, 460identify potentially applicable methods, 511phase 1: identify matching arity methodsapplicable by strict invocation, 511

phase 1: identify matching arity methodsapplicable by strict invocation, 511

compile-time declaration of a methodreference, 534, 534, 534, 535, 535compile-time step 2: determine methodSignature, 503, 503invocation applicability inference, 678more specific method inference, 686phase 2: identify matching arity methodsapplicable by loose invocation, 512phase 3: identify methods applicable byvariable arity invocation, 513, 513

phase 2: identify matching arity methodsapplicable by loose invocation, 512

Page 59: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

742

compile-time declaration of a methodreference, 534, 534compile-time step 2: determine methodSignature, 503, 503more specific method inference, 686phase 1: identify matching arity methodsapplicable by strict invocation, 512

phase 3: identify methods applicable byvariable arity invocation, 513

choosing the constructor and its arguments,483choosing the most specific method, 514compile-time declaration of a methodreference, 534, 534compile-time step 2: determine methodSignature, 503, 503invocation applicability inference, 678invocation type inference, 680more specific method inference, 686phase 2: identify matching arity methodsapplicable by loose invocation, 513

poly expressions, 460boolean conditional expressions, 579choosing the most specific method, 515class instance creation expressions, 478conditional operator ? :, 572, 572expression compatibility constraints, 663,663identify potentially applicable methods, 511lambda expressions, 594method reference expressions, 531more specific method inference, 687numeric conditional expressions, 579parenthesized expressions, 476

postfix decrement operator --, 544floating-point operations, 48, 49integer operations, 43, 44

normal and abrupt completion of evaluation,465operators ++ and --, 616variables, 80

postfix expressions, 542final variables, 86forms of expressions, 460syntactic classification of a name accordingto context, 151

postfix increment operator ++, 543floating-point operations, 48, 49integer operations, 43, 44normal and abrupt completion of evaluation,465operators ++ and --, 616variables, 80

potentially applicable methods, 509compile-time declaration of a methodreference, 533, 533, 534compile-time step 1: determine class orinterface to search, 500compile-time step 2: determine methodSignature, 503phase 1: identify matching arity methodsapplicable by strict invocation, 511phase 2: identify matching arity methodsapplicable by loose invocation, 512phase 3: identify methods applicable byvariable arity invocation, 513

predefined annotation types, 302prefix decrement operator --, 546

floating-point operations, 48, 49integer operations, 43, 44normal and abrupt completion of evaluation,465operators ++ and --, 616variables, 80

prefix increment operator ++, 546floating-point operations, 48, 49

Page 60: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

743

integer operations, 43, 44normal and abrupt completion of evaluation,465operators ++ and --, 616variables, 80

preparation of a class or interface type, 359kinds of variables, 83link test: verify, prepare, (optionally) resolve,354

preventing instantiation of a class, 266constructor declarations, 256

primary expressions, 471access to a protected member, 167forms of expressions, 460postfix expressions, 542

primitive types and values, 42class literals, 473conditional operator ? :, 572evaluation, denotation, and result, 459kinds of types and values, 41literals, 24reifiable types, 65unboxing conversion, 103variables, 80where types are used, 77

program exit, 374programs and program order, 641

happens-before order, 644synchronization order, 642

public classes, 384public interfaces, 400

Qqualified access to a protected constructor,167qualified expression names, 157

access control, 161

constant expressions, 606field access expressions, 494field declarations, 213members and constructors of parameterizedtypes, 64

qualified package names, 155qualified packageortypenames, 155qualified this, 475

declarations, 132syntactic classification of a name accordingto context, 150

qualified type names, 156access control, 161members and constructors of parameterizedtypes, 64single-static-import declarations, 184single-type-import declarations, 181static-import-on-demand declarations, 184type-import-on-demand declarations, 183

Rraw types, 66

assignment contexts, 108functional interfaces, 323invocation contexts, 113method reference expressions, 531reifiable types, 65subtyping among class and interface types,72type arguments of parameterized types, 61unchecked conversion, 103variables of reference type, 81where types are used, 77

reading final fields during construction, 654reclassification of contextually ambiguousnames, 152

method invocation expressions, 499

Page 61: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

744

reduction, 663invocation applicability inference, 678

reference conditional expressions, 580reference equality operators == and !=, 567

objects, 55reference type casting, 117

casting contexts, 115reference types and values, 52

class literals, 473evaluation, denotation, and result, 459initial values of variables, 87kinds of types and values, 41variables, 80

references, 7reifiable types, 64

@SafeVarargs, 307array creation expressions, 487array initializers, 335expressions and run-time checks, 463, 464formal parameters, 228method reference expressions, 531type comparison operator instanceof, 564

relational operators, 562constant expressions, 605

relationship to predefined classes andinterfaces, 7remainder operator %, 554

evaluate operands before operation, 468floating-point operations, 49integer operations, 44normal and abrupt completion of evaluation,465

repeatable annotation types, 298@Repeatable, 308evolution of annotation types, 403multiple annotations of the same type, 318

requirements in overriding, 289variables of reference type, 81

requirements in overriding and hiding, 246compile-time checking of Exceptions, 345method throws, 239requirements in overriding, 289, 289, 289type of a lambda expression, 603type of a method reference, 538variables of reference type, 81

resolution, 675invocation applicability inference, 679invocation type inference, 681

resolution of symbolic references, 359link test: verify, prepare, (optionally) resolve,355

return statement, 436break, continue, return, and throw statements,624constructor body, 260, 260instance initializers, 255interface method body, 291method body, 240normal and abrupt completion of statements,406static initializers, 255

run-time evaluation of array accessexpressions, 492

array access, 333evaluation order for other expressions, 471normal and abrupt completion of evaluation,465, 465

run-time evaluation of array creationexpressions, 488

evaluation order for other expressions, 471initial values of variables, 87kinds of variables, 83normal and abrupt completion of evaluation,464, 465

run-time evaluation of class instance creationexpressions, 484

Page 62: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

745

evaluation order for other expressions, 471normal and abrupt completion of evaluation,464throw statement, 439

run-time evaluation of lambda expressions,604

creation of new class instances, 366evaluation order for other expressions, 471normal and abrupt completion of evaluation,464

run-time evaluation of method invocation,520

evaluation order for other expressions, 471overloading, 251

run-time evaluation of method references,539

creation of new class instances, 366evaluation order for other expressions, 471normal and abrupt completion of evaluation,464

run-time handling of an exception, 349expressions and run-time checks, 464initial values of variables, 87kinds of variables, 84throw statement, 437try statement, 443

Sscope of a declaration, 139

basic for statement, 427class body and member declarations, 206class declarations, 191class literals, 474compile-time step 1: determine class orinterface to search, 500enhanced for statement, 430, 430enum constants, 268

field declarations, 213formal parameters, 228forward references during field initialization,222generic classes and type parameters, 195generic constructors, 259generic interfaces and type parameters, 280generic methods, 237import declarations, 180interface body and member declarations, 282interface declarations, 278lambda parameters, 598local class declarations, 407local variable declarators and types, 410member type declarations, 254method declarations, 226named packages, 178reclassification of contextually ambiguousnames, 152, 153simple package names, 155top level type declarations, 185try statement, 442try-with-resources, 448type variables, 57

semantics of final fields, 654separators, 38

lexical grammar, 9shadowing, 144

compile-time step 1: determine class orinterface to search, 500obscuring, 147scope of a declaration, 139simple expression names, 156

shadowing and obscuring, 142basic for statement, 427class body and member declarations, 206class declarations, 191enhanced for statement, 430

Page 63: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

746

enum constants, 268field declarations, 213formal parameters, 228generic classes and type parameters, 195generic constructors, 259import declarations, 180interface declarations, 278lambda parameters, 598local class declarations, 407local variable declarators and types, 410member type declarations, 254method declarations, 226named packages, 178top level type declarations, 185try statement, 442try-with-resources, 448

shared variables, 640happens-before order, 644

shift operators, 561constant expressions, 605integer operations, 43unary numeric promotion, 125

simple assignment operator =, 582assignment contexts, 109expressions and run-time checks, 463, 464normal and abrupt completion of evaluation,465, 465

simple expression names, 156constant expressions, 606field access expressions, 494

simple method names, 160method declarations, 226

simple package names, 155simple packageortypenames, 155simple type names, 156single-element annotations, 312

annotation type elements, 295annotations, 308

single-static-import declarations, 184declarations, 130, 131identify potentially applicable methods, 509import declarations, 180reclassification of contextually ambiguousnames, 153, 153scope of a declaration, 139simple method names, 160single-type-import declarations, 181syntactic classification of a name accordingto context, 150

single-type-import declarations, 180declarations, 130, 131import declarations, 180reclassification of contextually ambiguousnames, 153scope of a declaration, 139single-static-import declarations, 184syntactic classification of a name accordingto context, 150

sleep and yield, 636standalone expressions, 460

boolean conditional expressions, 579choosing the most specific method, 515class instance creation expressions, 478conditional operator ? :, 572, 572expression compatibility constraints, 663,663identify potentially applicable methods, 511lambda expressions, 594method reference expressions, 531more specific method inference, 687numeric conditional expressions, 579parenthesized expressions, 476

statements, 410static fields, 216, 393

generic classes and type parameters, 195kinds of variables, 83, 83

Page 64: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

747

when initialization occurs, 361static initializers, 255, 400

class body and member declarations, 206definite assignment and static initializers,628exception checking, 347final fields, 219generic classes and type parameters, 195inner classes and enclosing instances, 197return statement, 436simple expression names, 157static initializers, 400throw statement, 439

static member type declarations, 254anonymous class declarations, 485class modifiers, 191generic classes and type parameters, 195interface modifiers, 278, 279

static methods, 233, 398generic classes and type parameters, 195interface method declarations, 402simple expression names, 157

static-import-on-demand declarations, 184declarations, 130, 131identify potentially applicable methods, 509import declarations, 180reclassification of contextually ambiguousnames, 153, 153scope of a declaration, 139simple method names, 160syntactic classification of a name accordingto context, 150type-import-on-demand declarations, 183

strictfp classes, 194fp-strict expressions, 462

strictfp interfaces, 279fp-strict expressions, 462

strictfp methods, 235

fp-strict expressions, 462String concatenation operator +, 557

boolean type and boolean values, 51class String, 56constructor declarations, 256creation of new class instances, 366floating-point operations, 48integer operations, 44normal and abrupt completion of evaluation,464objects, 53, 54String contexts, 114types, classes, and interfaces, 88

String contexts, 114boolean type and boolean values, 51

String conversion, 105String concatenation operator +, 557String contexts, 114

String literals, 35class String, 56comments, 22constant expressions, 605creation of new class instances, 366escape sequences for character and Stringliterals, 37lexical literals, 473reference equality operators == and !=, 567unicode, 16

strings, 56lexical literals, 473literals, 24objects, 53String literals, 35, 36

subsequent modification of final fields, 655subtyping, 71

assignment contexts, 108checked casts and unchecked casts, 121choosing the most specific method, 514

Page 65: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

748

constraint formulas, 661invocation contexts, 113method throws, 238narrowing reference conversion, 99parameterized types, 59subtyping constraints, 668type arguments of parameterized types, 61,61widening reference conversion, 99

subtyping among array types, 73array types, 330

subtyping among class and interface types, 71try statement, 442

subtyping among primitive types, 71subtyping constraints, 668superclasses and subclasses, 200

class members, 206class Object, 55enum types, 267final classes, 194kinds of variables, 83loading process, 357subtyping among class and interface types,72syntactic classification of a name accordingto context, 150where types are used, 76, 77

superclasses and superinterfaces, 384loading process, 357superinterfaces, 401verification of the binary representation, 359

superinterfaces, 202, 401checked casts at run time, 122class members, 206subtyping among class and interface types,72superinterfaces and subinterfaces, 281

syntactic classification of a name accordingto context, 150types, classes, and interfaces, 88where types are used, 76, 77

superinterfaces and subinterfaces, 280interface members, 282loading process, 357subtyping among class and interface types,72superclasses and subclasses, 202superinterfaces, 203syntactic classification of a name accordingto context, 150where types are used, 76, 77

switch statement, 419scope of a declaration, 140, 140switch statements, 621

switch statements, 621synchronization, 632

objects, 55synchronized methods, 235synchronized statement, 439volatile fields, 220

synchronization order, 642actions, 640interaction with the memory model, 372

synchronized methods, 235, 398class Object, 56synchronization, 632synchronized statement, 440

synchronized statement, 439create frame, synchronize, transfer control,528objects, 55synchronization, 632synchronized statements, 624

synchronized statements, 624

Page 66: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

749

syntactic classification of a name according tocontext, 149

access control, 161declarations, 132reference types and values, 53

syntactic grammar, 10compilation units, 177input elements and tokens, 20lexical translations, 16

syntax, 689

Tthis, 474

field initialization, 221, 222initialization of fields in interfaces, 285instance initializers, 255static initializers, 256static methods, 234

threads and locks, 631objects, 55throw statement, 437

throw statement, 437break, continue, return, and throw statements,624causes of Exceptions, 343exception analysis of statements, 346initial values of variables, 87kinds of variables, 84normal and abrupt completion of statements,406, 406run-time handling of an exception, 349

top level type declarations, 185class instance creation expressions, 477class modifiers, 191compilation units, 177determining accessibility, 163form of a binary, 377

host support for packages, 175interface modifiers, 279package members, 173, 174scope of a declaration, 139, 139, 139shadowing, 146single-static-import declarations, 184single-type-import declarations, 181when initialization occurs, 361

transient fields, 219, 393try statement, 440

@Target, 303compile-time checking of Exceptions, 345declarations, 131, 132definite assignment and parameters, 626exception analysis of statements, 347expressions and run-time checks, 463, 464final variables, 85initial values of variables, 87kinds of variables, 84labeled statements, 413method throws, 239reclassification of contextually ambiguousnames, 152run-time handling of an exception, 349scope of a declaration, 141shadowing and obscuring, 142shared variables, 640syntactic classification of a name accordingto context, 151throw statement, 437, 438, 438try statements, 624where types are used, 76, 78

try statements, 624try-catch statement, 444

try statement, 443try-catch-finally statement, 445

try statement, 443try-finally statement, 445

Page 67: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

750

try statement, 443try-with-resources, 447

@Target, 303final variables, 85local variable declaration statements, 409scope of a declaration, 141syntactic classification of a name accordingto context, 150try statement, 444where types are used, 76

try-with-resources (basic), 448try-with-resources (extended), 451type arguments of parameterized types, 60

capture conversion, 103checked casts and unchecked casts, 121class instance creation expressions, 477, 477constraint formulas, 661explicit constructor invocations, 261method invocation expressions, 500method reference expressions, 530reference types and values, 52reifiable types, 65subtyping among class and interface types,72subtyping constraints, 669type equality constraints, 670types, classes, and interfaces, 89unchecked conversion, 103where types are used, 77

type comparison operator instanceof, 564expressions and run-time checks, 463objects, 54syntactic classification of a name accordingto context, 151where types are used, 76, 78

type compatibility constraints, 667type equality constraints, 670type erasure, 64

assignment contexts, 109cast expressions, 549checked casts and unchecked casts, 122checked casts at run time, 122choosing the most specific method, 516class type parameters, 385compile-time step 3: is the chosen methodappropriate?, 519constructor Signature, 258create frame, synchronize, transfer control,528declarations, 131evaluate arguments, 522field declarations, 390form of a binary, 378, 379, 380invocation contexts, 114method and constructor formal parameters,396method and constructor type parameters, 395method result type, 396method Signature, 230raw types, 66requirements in overriding and hiding, 246type variables, 58

type inference, 659compile-time step 2: determine methodSignature, 504generic constructors, 259generic methods, 237

type of a constructor, 259members and constructors of parameterizedtypes, 63

type of a lambda expression, 602checked exception constraints, 671expression compatibility constraints, 664invocation type inference, 682, 683lambda parameters, 597

type of a method reference, 537

Page 68: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

751

checked exception constraints, 672type of an expression, 461type variables, 57

class literals, 474field declarations, 390generic classes and type parameters, 194generic constructors, 259generic interfaces and type parameters, 279generic methods, 237intersection types, 70method and constructor formal parameters,396method result type, 396reference types and values, 52type erasure, 64types, classes, and interfaces, 89where types are used, 77

type-import-on-demand declarations, 183declarations, 130import declarations, 180reclassification of contextually ambiguousnames, 153scope of a declaration, 139shadowing, 146static-import-on-demand declarations, 185syntactic classification of a name accordingto context, 152

types, 41capture conversion, 103lexical literals, 473literals, 24null literal, 38throw statement, 438

types, classes, and interfaces, 88types, values, and variables, 41

Uunary minus operator -, 547

constant expressions, 605floating-point operations, 48integer literals, 30, 30integer operations, 43unary numeric promotion, 125

unary numeric promotion, 124array access, 333array access expressions, 491array creation expressions, 487bitwise complement operator ~, 548numeric contexts, 124shift operators, 561unary minus operator -, 547unary plus operator +, 547

unary operators, 544final variables, 86

unary plus operator +, 547constant expressions, 605floating-point operations, 48integer operations, 43unary numeric promotion, 125

unboxing conversion, 102additive operators, 556, 556array creation expressions, 487assert statement, 418assignment contexts, 108binary numeric promotion, 125bitwise complement operator ~, 548boolean equality operators == and !=, 567boolean logical operators &, ^, and |, 569casting contexts, 115, 115, 115conditional operator ? :, 572, 579conditional-and operator &&, 570, 570conditional-or operator ||, 571, 571do statement, 424

Page 69: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

INDEX

752

equality operators, 565floating-point operations, 49if-then statement, 415if-then-else statement, 416integer bitwise operators &, ^, and |, 568integer operations, 44invocation contexts, 113iteration of for statement, 427logical complement operator !, 548multiplicative operators, 550numeric contexts, 124numerical comparison operators <, <=, >, and>=, 563numerical equality operators == and !=, 566postfix decrement operator --, 544postfix increment operator ++, 543prefix decrement operator --, 546prefix increment operator ++, 546switch statement, 421unary minus operator -, 547unary numeric promotion, 124, 124unary plus operator +, 547while statement, 423

unchecked conversion, 103@SafeVarargs, 307assignment contexts, 108casting contexts, 115, 115invocation contexts, 113method result, 238type compatibility constraints, 668variables of reference type, 81

unicode, 15character literals, 34lexical grammar, 9primitive types and values, 42unicode escapes, 17

unicode escapes, 17

escape sequences for character and Stringliterals, 38input elements and tokens, 19lexical translations, 16unicode, 16

unloading of classes and interfaces, 373kinds of variables, 83

unnamed packages, 179compilation units, 177

unreachable statements, 452final fields and static constant variables, 391instance initializers, 255lambda body, 599static initializers, 255

uses of inference, 677

Vvalue set conversion, 106

assignment contexts, 109binary numeric promotion, 126casting contexts, 115compound assignment operators, 588, 590create frame, synchronize, transfer control,528evaluation, denotation, and result, 459floating-point types, formats, and values, 45fp-strict expressions, 462invocation contexts, 113simple assignment operator =, 583, 584unary minus operator -, 547unary numeric promotion, 124

variables, 80evaluation, denotation, and result, 459

variables of primitive type, 81variables of reference type, 81

@SafeVarargs, 307type of an expression, 461

Page 70: The Java Language Specificationptgmedia.pearsoncmg.com/images/9780133900699/... · The Java ® Language ... 6.6 Access Control 161 6.6.1 Determining Accessibility 162 6.6.2 Details

753

variables, 80verification of the binary representation, 358

link test: verify, prepare, (optionally) resolve,354

volatile fields, 220happens-before order, 644synchronization order, 642

Wwait, 633

happens-before order, 643wait sets and notification, 632

class Object, 56well-formed executions, 647

executions, 646what binary compatibility is and is not, 382when initialization occurs, 361

final variables, 85initialize test: execute initializers, 355

when reference types are the same, 56checked casts at run time, 122constraint formulas, 661type equality constraints, 670

where annotations may appear, 313annotation types, 292annotations, 308class modifiers, 191constructor modifiers, 258enum constants, 268field (constant) declarations, 283field modifiers, 215formal parameters, 228generic classes and type parameters, 195generic interfaces and type parameters, 280interface modifiers, 278lambda parameters, 598local variable declaration statements, 409

method declarations, 286method modifiers, 231named packages, 178

where types are used, 75@Target, 303lexical translations, 17syntactic classification of a name accordingto context, 150where annotations may appear, 313

while statement, 423boolean type and boolean values, 51while statements, 621

while statements, 621white space, 20

input elements and tokens, 20lexical grammar, 9lexical translations, 16

widening and narrowing primitiveconversion, 99

casting contexts, 115widening primitive conversion, 94

assignment contexts, 107binary numeric promotion, 126casting contexts, 115, 115invocation contexts, 112, 113numeric contexts, 124unary numeric promotion, 124, 124widening and narrowing primitiveconversion, 99

widening reference conversion, 99assignment contexts, 107casting contexts, 115, 115floating-point operations, 48integer operations, 44invocation contexts, 113, 113

word tearing, 657write-protected fields, 656