When testing that one applicable method is more specific than another (§15.12.2.5), where the second method is generic, it is necessary to test whether some instantiation of the second method's type parameters can be inferred to make the first method more specific than the second.
Let m1 be the first method and m2 be the second method. Where m2 has type parameters P1, ..., Pp, let α1, ..., αp be inference variables, and let θ be the substitution [P1:=α1, ..., Pp:=αp].
Let e1, ..., ek be the argument expressions of the corresponding invocation. Then:
• If m1 and m2 are applicable by strict or loose invocation (§15.12.2.2, §15.12.2.3), then let S1, ..., Sk be the formal parameter types of m1, and let T1, ..., Tk be the result of θ applied to the formal parameter types of m2.
• If m1 and m2 are applicable by variable arity invocation (§15.12.2.4), then let S1, ...,
Sk be the first k variable arity parameter types of m1, and let T1, ..., Tk be the result of θ applied to the first k variable arity parameter types of m2.
Note that no substitution is applied to S1, ..., Sk; even if m1 is generic, the type parameters of m1 are treated as type variables, not inference variables.
The process to determine if m1 is more specific than m2 is as follows:
• First, an initial bound set, B, is constructed from the declared bounds of P1, ...,
Pp, as specified in §18.1.3.
• Second, for all i (1 ≤ i ≤ k), a set of constraint formulas or bounds is generated.
If Ti is a proper type, the result is true if Si is more specific than Ti for ei
(§15.12.2.5), and false otherwise. (Note that Si is always a proper type.) Otherwise, if Ti is not a functional interface type, the constraint formula ‹Si<:
Ti› is generated.
Otherwise, Ti is a parameterization of a functional interface, I. It must be determined whether Si satisfies the following five constraints:
– Si is a functional interface type.
TYPE INFERENCE Uses of Inference 18.5
– Si is not a superinterface of I, nor a parameterization of a superinterface of I. – Si is not a subinterface of I, nor a parameterization of a subinterface of I. – If Si is an intersection type, at least one element of the intersection is not a
superinterface of I, nor a parameterization of a superinterface of I.
– If Si is an intersection type, no element of the intersection is a subinterface of
I, nor a parameterization of a subinterface of I.
If all of the above are true, then the following constraint formulas or bounds are generated (where U1 ... Uk and R1 are the parameter types and return type of the function type of the capture of Si, and V1 ... Vk and R2 are the parameter types and return type of the function type of Ti):
– If ei is an explicitly typed lambda expression:
› If R2 is void, true.
› Otherwise, if R1 and R2 are functional interface types, and neither interface is a subinterface of the other, then these rules are applied recursively to R1
and R2, for each result expression in ei.
› Otherwise, if R1 is a primitive type and R2 is not, and each result expression of ei is a standalone expression (§15.2) of a primitive type, true.
› Otherwise, if R2 is a primitive type and R1 is not, and each result expression of
ei is either a standalone expression of a reference type or a poly expression, true.
› Otherwise, ‹R1<:R2›.
– If ei is an exact method reference:
› For all j (1 ≤ j ≤ k), ‹Uj = Vj›.
› If R2 is void, true.
› Otherwise, if R1 is a primitive type and R2 is not, and the compile-time declaration for ei has a primitive return type, true.
› Otherwise if R2 is a primitive type and R1 is not, and the compile-time declaration for ei has a reference return type, true.
› Otherwise, ‹R1<:R2›.
– If ei is a parenthesized expression, these rules are applied recursively to the contained expression.
18.5 Uses of Inference TYPE INFERENCE
– If ei is a conditional expression, these rules are applied recursively to each of the second and third operands.
– Otherwise, false.
If the five constraints on Si are not satisfied, the constraint formula ‹Si<:Ti› is generated instead.
• Third, if m2 is applicable by variable arity invocation and has k+1 parameters, then where Sk+1 is the k+1'th variable arity parameter type of m1 and Tk+1 is the result of θ applied to the k+1'th variable arity parameter type of m2, the constraint
‹Sk+1<:Tk+1› is generated.
• Fourth, the generated bounds and constraint formulas are reduced and incorporated with B to produce a bound set B'.
If B' does not contain the bound false, and resolution of all the inference variables in B' succeeds, then m1 is more specific than m2.
Otherwise, m1 is not more specific than m2.
C H A P T E R 19
Syntax
THIS chapter repeats the syntactic grammar given in Chapters 4, 6-10, 14, and 15, as well as key parts of the lexical grammar from Chapter 3, using the notation from §2.4.
Productions from §3 (Lexical Structure) Identifier:
IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral IdentifierChars:
JavaLetter {JavaLetterOrDigit}
JavaLetter:
any Unicode character that is a "Java letter"
JavaLetterOrDigit:
any Unicode character that is a "Java letter-or-digit"
Literal:
IntegerLiteral FloatingPointLiteral BooleanLiteral CharacterLiteral StringLiteral NullLiteral
SYNTAX
Productions from §4 (Types, Values, and Variables) Type:
PrimitiveType ReferenceType PrimitiveType:
{Annotation} NumericType {Annotation} boolean
NumericType:
IntegralType FloatingPointType IntegralType: one of
byteshortintlongchar
FloatingPointType: one of
floatdouble
ReferenceType:
ClassOrInterfaceType TypeVariable
ArrayType
ClassOrInterfaceType:
ClassType InterfaceType ClassType:
{Annotation} Identifier [TypeArguments]
ClassOrInterfaceType . {Annotation} Identifier [TypeArguments]
InterfaceType:
ClassType TypeVariable:
{Annotation} Identifier
SYNTAX
ArrayType:
PrimitiveType Dims
ClassOrInterfaceType Dims TypeVariable Dims
Dims:
{Annotation} [] {{Annotation} []} TypeParameter:
{TypeParameterModifier} Identifier [TypeBound]
TypeBound:
extends TypeVariable
extends ClassOrInterfaceType {AdditionalBound}
AdditionalBound:
& InterfaceType TypeArguments:
< TypeArgumentList >
TypeArgumentList:
TypeArgument {, TypeArgument}
TypeArgument:
ReferenceType Wildcard Wildcard:
{Annotation} ? [WildcardBounds]
WildcardBounds:
extends ReferenceType
super ReferenceType
SYNTAX
Productions from §7 (Packages) CompilationUnit:
[PackageDeclaration] {ImportDeclaration} {TypeDeclaration}
PackageDeclaration:
{PackageModifier} package Identifier {. Identifier} ;
PackageModifier:
Annotation ImportDeclaration:
SingleTypeImportDeclaration TypeImportOnDemandDeclaration SingleStaticImportDeclaration StaticImportOnDemandDeclaration SingleTypeImportDeclaration:
import TypeName ;
TypeImportOnDemandDeclaration:
import PackageOrTypeName .*;
SingleStaticImportDeclaration:
importstatic TypeName . Identifier ;
StaticImportOnDemandDeclaration:
importstatic TypeName .*;
TypeDeclaration:
ClassDeclaration InterfaceDeclaration
;
SYNTAX
Productions from §8 (Classes) ClassDeclaration:
NormalClassDeclaration EnumDeclaration NormalClassDeclaration:
{ClassModifier} class Identifier [TypeParameters]
[Superclass] [Superinterfaces] ClassBody ClassModifier: one of
Annotation publicprotectedprivate
abstractstaticfinalstrictfp
TypeParameters:
< TypeParameterList >
TypeParameterList:
TypeParameter {, TypeParameter}
Superclass:
extends ClassType Superinterfaces:
implements InterfaceTypeList InterfaceTypeList:
InterfaceType {, InterfaceType}
ClassBody:
{ {ClassBodyDeclaration} }
ClassBodyDeclaration:
ClassMemberDeclaration InstanceInitializer StaticInitializer
ConstructorDeclaration
SYNTAX
ClassMemberDeclaration:
FieldDeclaration MethodDeclaration ClassDeclaration InterfaceDeclaration
;
FieldDeclaration:
{FieldModifier} UnannType VariableDeclaratorList ;
FieldModifier: one of
Annotation publicprotectedprivate
staticfinaltransientvolatile
VariableDeclaratorList:
VariableDeclarator {, VariableDeclarator}
VariableDeclarator:
VariableDeclaratorId [= VariableInitializer]
VariableDeclaratorId:
Identifier [Dims]
VariableInitializer:
Expression ArrayInitializer
SYNTAX
UnannType:
UnannPrimitiveType UnannReferenceType UnannPrimitiveType:
NumericType
boolean
UnannReferenceType:
UnannClassOrInterfaceType UnannTypeVariable
UnannArrayType
UnannClassOrInterfaceType:
UnannClassType UnannInterfaceType UnannClassType:
Identifier [TypeArguments]
UnannClassOrInterfaceType . {Annotation} Identifier [TypeArguments]
UnannInterfaceType:
UnannClassType UnannTypeVariable:
Identifier UnannArrayType:
UnannPrimitiveType Dims
UnannClassOrInterfaceType Dims UnannTypeVariable Dims
SYNTAX
MethodDeclaration:
{MethodModifier} MethodHeader MethodBody MethodModifier: one of
Annotation publicprotectedprivate
abstractstaticfinalsynchronizednativestrictfp
MethodHeader:
Result MethodDeclarator [Throws]
TypeParameters {Annotation} Result MethodDeclarator [Throws]
Result:
UnannType
void
MethodDeclarator:
Identifier ( [FormalParameterList] ) [Dims]
FormalParameterList:
FormalParameters , LastFormalParameter LastFormalParameter
FormalParameters:
FormalParameter {, FormalParameter}
ReceiverParameter {, FormalParameter}
FormalParameter:
{VariableModifier} UnannType VariableDeclaratorId VariableModifier: one of
Annotation final
LastFormalParameter:
{VariableModifier} UnannType {Annotation} ... VariableDeclaratorId FormalParameter
ReceiverParameter:
{Annotation} UnannType [Identifier .] this
SYNTAX
Throws:
throws ExceptionTypeList ExceptionTypeList:
ExceptionType {, ExceptionType}
ExceptionType:
ClassType TypeVariable MethodBody:
Block
;
InstanceInitializer:
Block
StaticInitializer:
static Block
ConstructorDeclaration:
{ConstructorModifier} ConstructorDeclarator [Throws] ConstructorBody ConstructorModifier: one of
Annotation publicprotectedprivate
ConstructorDeclarator:
[TypeParameters] SimpleTypeName ( [FormalParameterList] ) ConstructorBody:
{ [ExplicitConstructorInvocation] [BlockStatements] }
ExplicitConstructorInvocation:
[TypeArguments] this( [ArgumentList] ); [TypeArguments] super( [ArgumentList] );
ExpressionName . [TypeArguments] super( [ArgumentList] ); Primary . [TypeArguments] super( [ArgumentList] );
SYNTAX
EnumDeclaration:
{ClassModifier} enum Identifier [Superinterfaces] EnumBody EnumBody:
{ [EnumConstantList] [,] [EnumBodyDeclarations] }
EnumConstantList:
EnumConstant {, EnumConstant}
EnumConstant:
{EnumConstantModifier} Identifier [( [ArgumentList] )] [ClassBody]
EnumConstantModifier:
Annotation
EnumBodyDeclarations:
; {ClassBodyDeclaration}
SYNTAX
Productions from §9 (Interfaces) InterfaceDeclaration:
NormalInterfaceDeclaration AnnotationTypeDeclaration NormalInterfaceDeclaration:
{InterfaceModifier} interface Identifier [TypeParameters]
[ExtendsInterfaces] InterfaceBody InterfaceModifier: one of
Annotation publicprotectedprivate
abstractstaticstrictfp
ExtendsInterfaces:
extends InterfaceTypeList InterfaceBody:
{ {InterfaceMemberDeclaration} }
InterfaceMemberDeclaration:
ConstantDeclaration
InterfaceMethodDeclaration ClassDeclaration
InterfaceDeclaration
;
ConstantDeclaration:
{ConstantModifier} UnannType VariableDeclaratorList ;
ConstantModifier: one of Annotation public staticfinal
InterfaceMethodDeclaration:
{InterfaceMethodModifier} MethodHeader MethodBody InterfaceMethodModifier: one of
Annotation public
abstractdefaultstaticstrictfp
SYNTAX
AnnotationTypeDeclaration:
{InterfaceModifier} @interface Identifier AnnotationTypeBody AnnotationTypeBody:
{ {AnnotationTypeMemberDeclaration} }
AnnotationTypeMemberDeclaration:
AnnotationTypeElementDeclaration ConstantDeclaration
ClassDeclaration InterfaceDeclaration
;
AnnotationTypeElementDeclaration:
{AnnotationTypeElementModifier} UnannType Identifier () [Dims]
[DefaultValue] ;
AnnotationTypeElementModifier: one of Annotation public
abstract
DefaultValue:
default ElementValue
SYNTAX
Annotation:
NormalAnnotation MarkerAnnotation SingleElementAnnotation NormalAnnotation:
@ TypeName ( [ElementValuePairList] )
ElementValuePairList:
ElementValuePair {, ElementValuePair}
ElementValuePair:
Identifier = ElementValue ElementValue:
ConditionalExpression ElementValueArrayInitializer Annotation
ElementValueArrayInitializer:
{ [ElementValueList] [,] }
ElementValueList:
ElementValue {, ElementValue}
MarkerAnnotation:
@ TypeName
SingleElementAnnotation:
@ TypeName ( ElementValue )
SYNTAX
Productions from §10 (Arrays) ArrayInitializer:
{ [VariableInitializerList] [,] }
VariableInitializerList:
VariableInitializer {, VariableInitializer}
SYNTAX
Productions from §14 (Blocks and Statements) Block:
{ [BlockStatements] }
BlockStatements:
BlockStatement {BlockStatement}
BlockStatement:
LocalVariableDeclarationStatement ClassDeclaration
Statement
LocalVariableDeclarationStatement:
LocalVariableDeclaration ;
LocalVariableDeclaration:
{VariableModifier} UnannType VariableDeclaratorList Statement:
StatementWithoutTrailingSubstatement LabeledStatement
IfThenStatement IfThenElseStatement WhileStatement ForStatement StatementNoShortIf:
StatementWithoutTrailingSubstatement LabeledStatementNoShortIf
IfThenElseStatementNoShortIf WhileStatementNoShortIf ForStatementNoShortIf
SYNTAX
StatementWithoutTrailingSubstatement:
Block
EmptyStatement ExpressionStatement AssertStatement SwitchStatement DoStatement BreakStatement ContinueStatement ReturnStatement SynchronizedStatement ThrowStatement TryStatement EmptyStatement:
;
LabeledStatement:
Identifier : Statement LabeledStatementNoShortIf:
Identifier : StatementNoShortIf ExpressionStatement:
StatementExpression ;
StatementExpression:
Assignment
PreIncrementExpression PreDecrementExpression PostIncrementExpression PostDecrementExpression MethodInvocation
ClassInstanceCreationExpression
SYNTAX
IfThenStatement:
if( Expression ) Statement IfThenElseStatement:
if( Expression ) StatementNoShortIf else Statement IfThenElseStatementNoShortIf:
if( Expression ) StatementNoShortIf else StatementNoShortIf AssertStatement:
assert Expression ;
assert Expression : Expression ;
SwitchStatement:
switch( Expression ) SwitchBlock SwitchBlock:
{ {SwitchBlockStatementGroup} {SwitchLabel} }
SwitchBlockStatementGroup:
SwitchLabels BlockStatements SwitchLabels:
SwitchLabel {SwitchLabel}
SwitchLabel:
case ConstantExpression : case EnumConstantName : default:
EnumConstantName:
Identifier WhileStatement:
while( Expression ) Statement WhileStatementNoShortIf:
while( Expression ) StatementNoShortIf DoStatement:
do Statement while( Expression );
SYNTAX
ForStatement:
BasicForStatement EnhancedForStatement ForStatementNoShortIf:
BasicForStatementNoShortIf EnhancedForStatementNoShortIf BasicForStatement:
for( [ForInit] ; [Expression] ; [ForUpdate] ) Statement BasicForStatementNoShortIf:
for( [ForInit] ; [Expression] ; [ForUpdate] ) StatementNoShortIf ForInit:
StatementExpressionList LocalVariableDeclaration ForUpdate:
StatementExpressionList StatementExpressionList:
StatementExpression {, StatementExpression}
EnhancedForStatement:
for( {VariableModifier} UnannType VariableDeclaratorId
: Expression )
Statement
EnhancedForStatementNoShortIf:
for( {VariableModifier} UnannType VariableDeclaratorId
: Expression )
StatementNoShortIf BreakStatement:
break [Identifier] ;
ContinueStatement:
continue [Identifier] ;
ReturnStatement:
return [Expression] ;
SYNTAX
ThrowStatement:
throw Expression ;
SynchronizedStatement:
synchronized( Expression ) Block TryStatement:
try Block Catches
try Block [Catches] Finally TryWithResourcesStatement Catches:
CatchClause {CatchClause}
CatchClause:
catch( CatchFormalParameter ) Block CatchFormalParameter:
{VariableModifier} CatchType VariableDeclaratorId CatchType:
UnannClassType {| ClassType}
Finally:
finally Block
TryWithResourcesStatement:
try ResourceSpecification Block [Catches] [Finally]
ResourceSpecification:
( ResourceList [;] )
ResourceList:
Resource {; Resource}
Resource:
{VariableModifier} UnannType VariableDeclaratorId = Expression
SYNTAX
Productions from §15 (Expressions) Primary:
PrimaryNoNewArray ArrayCreationExpression PrimaryNoNewArray:
Literal
TypeName {[]} .class void.class
this
TypeName .this ( Expression )
ClassInstanceCreationExpression FieldAccess
ArrayAccess MethodInvocation MethodReference
ClassInstanceCreationExpression:
new [TypeArguments] {Annotation} Identifier
[TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody]
ExpressionName .new [TypeArguments] {Annotation} Identifier [TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody]
Primary .new [TypeArguments] {Annotation} Identifier
[TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody]
TypeArgumentsOrDiamond:
TypeArguments
<>
FieldAccess:
Primary . Identifier
super. Identifier
TypeName .super. Identifier ArrayAccess:
ExpressionName [ Expression ]
PrimaryNoNewArray [ Expression ]
SYNTAX
MethodInvocation:
MethodName ( [ArgumentList] )
TypeName . [TypeArguments] Identifier ( [ArgumentList] )
ExpressionName . [TypeArguments] Identifier ( [ArgumentList] )
Primary . [TypeArguments] Identifier ( [ArgumentList] ) super. [TypeArguments] Identifier ( [ArgumentList] )
TypeName .super. [TypeArguments] Identifier ( [ArgumentList] )
ArgumentList:
Expression {, Expression}
MethodReference:
ExpressionName :: [TypeArguments] Identifier ReferenceType :: [TypeArguments] Identifier Primary :: [TypeArguments] Identifier
super:: [TypeArguments] Identifier
TypeName .super:: [TypeArguments] Identifier ClassType :: [TypeArguments] new
ArrayType ::new
ArrayCreationExpression:
new PrimitiveType DimExprs [Dims]
new ClassOrInterfaceType DimExprs [Dims]
new PrimitiveType Dims ArrayInitializer
new ClassOrInterfaceType Dims ArrayInitializer DimExprs:
DimExpr {DimExpr}
DimExpr:
{Annotation} [ Expression ]
SYNTAX
ConstantExpression:
Expression Expression:
LambdaExpression AssignmentExpression LambdaExpression:
LambdaParameters -> LambdaBody LambdaParameters:
Identifier
( [FormalParameterList] ) ( InferredFormalParameterList )
InferredFormalParameterList:
Identifier {, Identifier}
LambdaBody:
Expression Block
AssignmentExpression:
ConditionalExpression Assignment
Assignment:
LeftHandSide AssignmentOperator Expression LeftHandSide:
ExpressionName FieldAccess ArrayAccess
AssignmentOperator: one of
= *= /= %= += -= <<= >>= >>>= &= ^= |=
SYNTAX
ConditionalExpression:
ConditionalOrExpression
ConditionalOrExpression ? Expression : ConditionalExpression ConditionalOrExpression:
ConditionalAndExpression
ConditionalOrExpression || ConditionalAndExpression ConditionalAndExpression:
InclusiveOrExpression
ConditionalAndExpression && InclusiveOrExpression InclusiveOrExpression:
ExclusiveOrExpression
InclusiveOrExpression | ExclusiveOrExpression ExclusiveOrExpression:
AndExpression
ExclusiveOrExpression ^ AndExpression AndExpression:
EqualityExpression
AndExpression & EqualityExpression EqualityExpression:
RelationalExpression
EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression RelationalExpression:
ShiftExpression
RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression
RelationalExpression instanceof ReferenceType ShiftExpression:
AdditiveExpression
ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression
SYNTAX
AdditiveExpression:
MultiplicativeExpression
AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression MultiplicativeExpression:
UnaryExpression
MultiplicativeExpression * UnaryExpression MultiplicativeExpression / UnaryExpression MultiplicativeExpression % UnaryExpression UnaryExpression:
PreIncrementExpression PreDecrementExpression
+ UnaryExpression
- UnaryExpression
UnaryExpressionNotPlusMinus PreIncrementExpression:
++ UnaryExpression PreDecrementExpression:
-- UnaryExpression
UnaryExpressionNotPlusMinus:
PostfixExpression
~ UnaryExpression
! UnaryExpression CastExpression PostfixExpression:
Primary
ExpressionName
PostIncrementExpression PostDecrementExpression PostIncrementExpression:
PostfixExpression ++
PostDecrementExpression:
PostfixExpression --
SYNTAX
CastExpression:
( PrimitiveType ) UnaryExpression
( ReferenceType {AdditionalBound} ) UnaryExpressionNotPlusMinus
( ReferenceType {AdditionalBound} ) LambdaExpression
Index
Symbols
= operator, 583
assignment contexts, 109
expressions and run-time checks, 465, 466 normal and abrupt completion of evaluation, 467, 467
@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, 122 formal parameters, 228
requirements in overriding and hiding, 246 unchecked conversion, 103
@Target, 302
multiple annotations of the same type, 318 repeatable annotation types, 298
where annotations may appear, 313
A
abrupt completion of do statement, 427 do statement, 427
abrupt completion of for statement, 430
iteration of for statement, 430
abrupt completion of while statement, 426 while statement, 425
abstract classes, 192, 385 abstract methods, 232
anonymous class declarations, 487 array creation expressions, 489 final classes, 194
superinterfaces, 204 abstract interfaces, 279 abstract methods, 232, 398
abstract classes, 192 method body, 240 method declarations, 286 access control, 161
accessing superclass members using super, 499
class literals, 475 class modifiers, 191 constructor declarations, 256 default constructor, 265 enum body declarations, 269 explicit constructor invocations, 262 field access using a primary, 496
identify potentially applicable methods, 511 import declarations, 180
interface modifiers, 278 local class declarations, 409 member type declarations, 254 method declarations, 286 normal annotations, 309 objects, 54
qualified expression names, 158, 158, 158
INDEX
qualified type names, 156, 156 reference types and values, 53
requirements in overriding and hiding, 247 single-static-import declarations, 184 single-type-import declarations, 181 static-import-on-demand declarations, 184 superclasses and subclasses, 200
superinterfaces, 202
superinterfaces and subinterfaces, 280 type-import-on-demand declarations, 183 access to a protected member, 167 access to members and constructors, 389 accessing superclass members using super, 499
declarations, 132 field declarations, 213 field initialization, 221, 222
initialization of fields in interfaces, 285 instance initializers, 255
static methods, 234
syntactic classification of a name according to context, 150
actions, 642
synchronization order, 644 additive operators, 558
constant expressions, 606 integer operations, 43
additive operators (+ and -) for numeric types, 561
binary numeric promotion, 127 floating-point operations, 48
an array of characters is not a String, 339 annotation type elements, 293
@Target, 303 annotation types, 293 declarations, 130, 131, 131 marker annotations, 311 normal annotations, 309
single-element annotations, 312
syntactic classification of a name according to context, 150
where types are used, 76 annotation types, 292
@Target, 302 annotations, 308 declarations, 130
interface declarations, 278 annotations, 308
declarations, 132
defaults for annotation type elements, 297 syntactic classification of a name according to context, 150
anonymous class declarations, 487
class instance creation expressions, 479, 479 class modifiers, 191
definite assignment and anonymous classes, 629
enum constants, 268 form of a binary, 379
initialization of fields in interfaces, 285 inner classes and enclosing instances, 197 syntactic classification of a name according to context, 151
where types are used, 77, 78 anonymous constructors, 487
choosing the constructor and its arguments, 485
default constructor, 265 form of a binary, 383
argument lists are evaluated left-to-right, 472 array access, 332
array access expressions, 493 array access, 332
assignment operators, 583
compound assignment operators, 590 simple assignment operator =, 583
INDEX
syntactic classification of a name according to context, 151
unary numeric promotion, 126 array creation, 332
array creation and access expressions, 488 method reference expressions, 531 array creation expressions, 488
array creation, 332 array initializers, 335 objects, 53
syntactic classification of a name according to context, 151
unary numeric promotion, 126 where types are used, 77, 78 array initializers, 335
array creation, 332
definite assignment and array initializers, 628
normal and abrupt completion of evaluation, 466
objects, 53
run-time evaluation of array creation expressions, 489
array members, 336 declarations, 130, 130 happens-before order, 646 qualified expression names, 159 array store exception, 333
array variables, 332 assignment contexts, 109
expressions and run-time checks, 465, 466 normal and abrupt completion of evaluation, 467
variables, 81 array types, 330
annotation type elements, 294 enhanced for statement, 432 raw types, 66
reference types and values, 52 reifiable types, 65
where types are used, 77 array variables, 330
enhanced for statement, 433 formal parameters, 228 lambda parameters, 599 arrays, 329
array creation expressions, 488 kinds of variables, 84
when reference types are the same, 57 assert statement, 418
assert statements, 622
detailed initialization procedure, 367 when initialization occurs, 363 assert statements, 622
assignment contexts, 107 array initializers, 335 array store exception, 333 array variables, 332
class instance creation expressions, 479 execution of try-catch, 446
expressions and run-time checks, 465, 465 kinds of types and values, 42
lambda expressions, 596
method invocation expressions, 501 method reference expressions, 533 normal annotations, 310
reference conditional expressions, 581 return statement, 438
run-time evaluation of method references, 542
simple assignment operator =, 583, 584 switch statement, 422
throw statement, 439, 440 type of an expression, 463 variables, 81
assignment expressions, 617
INDEX
assignment operators, 582 assignment contexts, 107 assignment expressions, 617
evaluation order for other expressions, 473 field initialization, 221
final variables, 86 forms of expressions, 462 initial values of variables, 87
syntactic classification of a name according to context, 151
variables, 81
asynchronous Exceptions, 344 causes of Exceptions, 343
B
basic for statement, 428
@Target, 303 for statements, 624 scope of a declaration, 140
syntactic classification of a name according to context, 151
where types are used, 76 basic try-with-resources, 450 binary compatibility, 377 binary numeric promotion, 126
additive operators (+ and -) for numeric types, 561
division operator /, 554
integer bitwise operators &, ^, and |, 570 multiplicative operators, 552
numeric conditional expressions, 581 numeric contexts, 125
numerical comparison operators <, <=, >, and
>=, 565
numerical equality operators == and !=, 567 postfix decrement operator --, 546
postfix increment operator ++, 545
prefix decrement operator --, 548 prefix increment operator ++, 548 remainder operator %, 555 shift operators, 563
bitwise and logical operators, 569 constant expressions, 606 bitwise complement operator ~, 550
constant expressions, 606 integer operations, 43 unary numeric promotion, 126 blocks, 409, 619
blocks, 619
kinds of variables, 84 lambda body, 600
local class declarations, 409 scope of a declaration, 140 blocks and statements, 407
boolean conditional expressions, 580 boolean constant expressions, 615 boolean equality operators == and !=, 568
boolean type and boolean values, 51 boolean literals, 34
boolean type and boolean values, 51 boxing conversion, 101
constant expressions, 606 identifiers, 23
lexical literals, 475
boolean logical operators &, ^, and |, 571 boolean type and boolean values, 51 conditional-and operator &&, 571 conditional-or operator ||, 572 boolean type and boolean values, 51
boolean literals, 34 lexical literals, 475 bounds, 663
bounds involving capture conversion, 677 invocation applicability inference, 680 more specific method inference, 688
INDEX
reduction, 665
bounds involving capture conversion, 676 incorporation, 675
boxing conversion, 100 assignment contexts, 107 casting contexts, 115 class literals, 475
conditional operator ? :, 580 creation of new class instances, 368 floating-point operations, 49 integer operations, 44 invocation contexts, 113 invocation type inference, 682
normal and abrupt completion of evaluation, 467
numeric conditional expressions, 580 objects, 53
postfix decrement operator --, 546 postfix increment operator ++, 545 prefix decrement operator --, 548 prefix increment operator ++, 548 type compatibility constraints, 670, 670 break statement, 434
break, continue, return, and throw statements, 626
labeled statements, 415 names and identifiers, 137
normal and abrupt completion of statements, 408
break, continue, return, and throw statements, 626
C
capture conversion, 103 array access expressions, 493 assignment operators, 583 bounds, 664
cast expressions, 551
compile-time declaration of a method reference, 534, 536
compile-time step 3: is the chosen method appropriate?, 521
enhanced for statement, 432
expression compatibility constraints, 669, 669
field access using a primary, 496 function types, 325
intersection types, 70 least upper bound, 75
members and constructors of parameterized types, 63
parameterized types, 59
qualified expression names, 158, 158, 158, 159, 159
reference conditional expressions, 581 resolution, 678
simple expression names, 157
subtyping among class and interface types, 73
type arguments of parameterized types, 61 type of a method reference, 540
cast expressions, 550 array types, 330 casting contexts, 114
compile-time step 3: is the chosen method appropriate?, 520
constant expressions, 606
expressions and run-time checks, 465, 466 floating-point operations, 48
forms of expressions, 462 happens-before order, 646 integer operations, 44 intersection types, 70
normal and abrupt completion of evaluation, 467
INDEX
objects, 55
syntactic classification of a name according to context, 151
type comparison operator instanceof, 566 unary operators, 546
where types are used, 77 casting contexts, 114
boolean type and boolean values, 52 cast expressions, 551, 552
expressions and run-time checks, 465, 466 happens-before order, 646
kinds of types and values, 42 lambda expressions, 596
method reference expressions, 533 objects, 55
reference equality operators == and !=, 569 casting conversions to primitive types, 117 casting conversions to reference types, 118 causes of Exceptions, 343
character literals, 34 boxing conversion, 101 comments, 22
constant expressions, 606
escape sequences for character and String literals, 37
lexical literals, 475 unicode, 16
check accessibility of type and method, 524 run-time evaluation of method references, 542, 542, 543
checked casts and unchecked casts, 122 variables of reference type, 81 checked casts at run time, 123
checked casts and unchecked casts, 123 checked exception constraints, 673
choosing the constructor and its arguments, 483
anonymous constructors, 487
class instance creation expressions, 479 compile-time declaration of a method reference, 535
default constructor, 265
expression compatibility constraints, 666 formal parameters, 257
choosing the most specific method, 515 compile-time declaration of a method reference, 536, 536, 537
compile-time step 2: determine method Signature, 505
conditional operator ? :, 574, 574 method and constructor overloading, 401 more specific method inference, 688, 688 phase 1: identify matching arity methods applicable by strict invocation, 514 phase 2: identify matching arity methods applicable by loose invocation, 514 phase 3: identify methods applicable by variable arity invocation, 515
class body and member declarations, 205, 388 class members, 206
member type declarations, 254, 254 scope of a declaration, 139
what binary compatibility is and is not, 384 class declarations, 191
declarations, 130
reference types and values, 52 types, classes, and interfaces, 88 class instance creation expressions, 478
conditional operator ? :, 573, 574 constructor declarations, 256, 256 constructor overloading, 264 creation of new class instances, 367 exception analysis of expressions, 346 form of a binary, 381
forms of expressions, 462 functional interfaces, 319
INDEX
initial values of variables, 87, 87 instance initializers, 255 invocation contexts, 112 invocation type inference, 683 kinds of variables, 84
method reference expressions, 531 names and identifiers, 138 objects, 53, 53
return statement, 438
run-time handling of an exception, 350 String conversion, 106
syntactic classification of a name according to context, 151, 151, 151
types, classes, and interfaces, 88 where types are used, 76, 77, 78, 78 class literals, 475
declarations, 132 normal annotations, 310
syntactic classification of a name according to context, 150
class loading, 358
causes of Exceptions, 343 class literals, 476 load the class test, 356 class members, 206
abstract classes, 192 declarations, 130 function types, 323
members and constructors of parameterized types, 63
method invocation type, 518 class modifiers, 191
@Target, 302
anonymous class declarations, 487 local class declarations, 409
reference type casting, 119, 119, 119 class Object, 56
checked casts at run time, 124, 124
method invocation type, 518 class objects for arrays, 338
types, classes, and interfaces, 88 class String, 56
lexical literals, 475 literals, 24 objects, 53
String literals, 35, 36 class type parameters, 387 classes, 189
local class declarations, 409 package members, 173 qualified expression names, 158
reclassification of contextually ambiguous names, 153
top level type declarations, 185 comments, 21
input elements and tokens, 20 lexical grammar, 9
lexical translations, 16 line terminators, 19 unicode, 16 compilation units, 177
determining accessibility, 162 host support for packages, 175 observability of a package, 179 package members, 173
reclassification of contextually ambiguous names, 153, 153
scope of a declaration, 139 shadowing, 146
syntactic grammar, 10
compile-time checking of Exceptions, 345 checked exception constraints, 673
compile-time declaration of a method reference, 534
checked exception constraints, 674 choosing the most specific method, 516