[PDF] [PDF] Download PDF - Kotlin language specification

kotlin Function(R) is the unified supertype of all function types It is param- eterized over function return type R Built-in integer types Kotlin supports the following 



Previous PDF Next PDF





[PDF] Download PDF - Kotlin language specification

kotlin Function(R) is the unified supertype of all function types It is param- eterized over function return type R Built-in integer types Kotlin supports the following 



[PDF] Type inference - Kotlin language specification

ment/expression scope; • Function signature type inference, for inferring types of function return values and/or parameters Type inference is a type constraint 



[PDF] Expressions - Kotlin language specification

Otherwise, if the value is greater than maximum kotlin Int value (see The compareTo operator function must have return type kotlin Int, otherwise



[PDF] Integer types - Kotlin language specification

for a function returning nothing), but is different in that there is, in fact, a single value of Boolean is the boolean logic type of Kotlin, representing a value which



[PDF] functions - Kotlin language specification

parameters and default parameter values, just as regular functions Please refer componentN function has the same type as this property and returns the value  



[PDF] Download Kotlin 1430 documentation (PDF)

and there was no common function that would return the numeric value 4 for In Kotlin 1 4, you can use callable references to functions returning any type in 



[PDF] Type system - Kotlin language specification

Function kotlin Function(R) is the unified supertype of all function types It is param- eterized over function return type R Built-in integer types Kotlin supports the 



[PDF] GETTING STARTED WITH INTRODUCTION WHERE TO START

The return type of the main is Unit, also prefaced by a colon In case of a Unit Functions and variables in Kotlin may be declared at "top- level", i e directly 



[PDF] type inference - JetBrains

Contract: if the function returns a given value, a condition is satisfied isNullOrEmpty, isNullOrBlank kotlin test: assertTrue, assertFalse, assertNotNull check 



[PDF] raywenderlichcom Kotlin Cheat Sheet and Quick Reference

Kotlin Cheat Sheet and Quick Reference Version 1 0 Visit for more Android/ Kotlin resources and tutorials Function with parameters and return value

[PDF] kotlin mockk return multiple values

[PDF] kotlin online course

[PDF] kotlin oop cheat sheet

[PDF] kotlin programming by example "pdf"

[PDF] kotlin quick reference

[PDF] kotlin training

[PDF] kotlin tutorial android app

[PDF] kotlin tutorial android developer

[PDF] kotlin tutorial android for beginners pdf

[PDF] kotlin tutorial android javatpoint

[PDF] kotlin tutorial android pdf

[PDF] kotlin tutorial android studio pdf

[PDF] kotlin tutorial android tutorialspoint

[PDF] kotlin version

[PDF] kpmg balance sheet

Kotlin language specification

Version 1.8-rfc+0.1

Marat Akhin Mikhail Belyaev

ii

Contents

I Kotlin/Core 1

Introduction 3

Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Experimental features . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1 Syntax and grammar 7

1.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

1.2 Lexical grammar . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

1.2.1 Whitespace and comments . . . . . . . . . . . . . . . . . .

7

1.2.2 Keywords and operators . . . . . . . . . . . . . . . . . . .

8

1.2.3 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

1.2.4 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

1.2.5 String mode grammar . . . . . . . . . . . . . . . . . . . .

18

1.2.6 Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

19

1.3 Syntax grammar . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

1.4 Documentation comments . . . . . . . . . . . . . . . . . . . . . .

42

2 Type system 43

Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

2.1 Type kinds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

45

2.1.1 Built-in types . . . . . . . . . . . . . . . . . . . . . . . . .

46
kotlin.Any. . . . . . . . . . . . . . . . . . . . . . . . . .46 kotlin.Nothing. . . . . . . . . . . . . . . . . . . . . . .46 kotlin.Function. . . . . . . . . . . . . . . . . . . . . .46 Built-in integer types . . . . . . . . . . . . . . . . . . . . . 46
Array types . . . . . . . . . . . . . . . . . . . . . . . . . . 46

2.1.2 Classifier types . . . . . . . . . . . . . . . . . . . . . . . .

47
Simple classifier types . . . . . . . . . . . . . . . . . . . . 48
Parameterized classifier types . . . . . . . . . . . . . . . . 48
iii ivCONTENTS

2.1.3 Type parameters . . . . . . . . . . . . . . . . . . . . . . .

50
Function type parameters . . . . . . . . . . . . . . . . . . 51
Mixed-site variance . . . . . . . . . . . . . . . . . . . . . . 51
Declaration-site variance . . . . . . . . . . . . . . . . . . . 52
Use-site variance . . . . . . . . . . . . . . . . . . . . . . . 54

2.1.4 Type capturing . . . . . . . . . . . . . . . . . . . . . . . .

55

2.1.5 Type containment . . . . . . . . . . . . . . . . . . . . . .

60

2.1.6 Function types . . . . . . . . . . . . . . . . . . . . . . . .

61
Suspending function types . . . . . . . . . . . . . . . . . . 62

2.1.7 Flexible types . . . . . . . . . . . . . . . . . . . . . . . . .

63
Dynamic type . . . . . . . . . . . . . . . . . . . . . . . . . 64
Platform types . . . . . . . . . . . . . . . . . . . . . . . . 64

2.1.8 Nullable types . . . . . . . . . . . . . . . . . . . . . . . .

64
Nullability lozenge . . . . . . . . . . . . . . . . . . . . . . 65
Definitely non-nullable types . . . . . . . . . . . . . . . . 66

2.1.9 Intersection types . . . . . . . . . . . . . . . . . . . . . . .

67

2.1.10 Integer literal types . . . . . . . . . . . . . . . . . . . . .

67

2.1.11 Union types . . . . . . . . . . . . . . . . . . . . . . . . . .

67

2.2 Type contexts and scopes . . . . . . . . . . . . . . . . . . . . . .

68

2.2.1 Inner and nested type contexts . . . . . . . . . . . . . . .

68

2.3 Subtyping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

69

2.3.1 Subtyping rules . . . . . . . . . . . . . . . . . . . . . . . .

69

2.3.2 Subtyping for flexible types . . . . . . . . . . . . . . . . .

69

2.3.3 Subtyping for intersection types . . . . . . . . . . . . . . .

70

2.3.4 Subtyping for integer literal types . . . . . . . . . . . . .

70

2.3.5 Subtyping for nullable types . . . . . . . . . . . . . . . . .

71

2.4 Upper and lower bounds . . . . . . . . . . . . . . . . . . . . . . .

73

2.4.1 Least upper bound . . . . . . . . . . . . . . . . . . . . . .

73

2.4.2 Greatest lower bound . . . . . . . . . . . . . . . . . . . .

75

2.5 Type approximation . . . . . . . . . . . . . . . . . . . . . . . . .

76

2.6 Type decaying . . . . . . . . . . . . . . . . . . . . . . . . . . . .

76
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

3 Built-in types and their semantics 79

3.1kotlin.Any. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79

3.2kotlin.Nothing. . . . . . . . . . . . . . . . . . . . . . . . . . .80

3.3kotlin.Unit. . . . . . . . . . . . . . . . . . . . . . . . . . . . .80

3.4kotlin.Boolean. . . . . . . . . . . . . . . . . . . . . . . . . . .80

3.5 Built-in integer types . . . . . . . . . . . . . . . . . . . . . . . . .

80

3.5.1 Integer type widening . . . . . . . . . . . . . . . . . . . .

81

3.6 Built-in floating point arithmetic types . . . . . . . . . . . . . . .

82

3.7kotlin.Char. . . . . . . . . . . . . . . . . . . . . . . . . . . . .82

3.8kotlin.String. . . . . . . . . . . . . . . . . . . . . . . . . . . .83

3.9kotlin.Enum. . . . . . . . . . . . . . . . . . . . . . . . . . . . .83

3.10 Built-in array types . . . . . . . . . . . . . . . . . . . . . . . . . .

84

3.10.1 Specialized array types . . . . . . . . . . . . . . . . . . . .

84

CONTENTSv

3.11 Iterator types . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

85

3.11.1 Specialized iterator types . . . . . . . . . . . . . . . . . .

85

3.12kotlin.Throwable. . . . . . . . . . . . . . . . . . . . . . . . . .86

3.13kotlin.Comparable. . . . . . . . . . . . . . . . . . . . . . . . .86

3.14kotlin.Function. . . . . . . . . . . . . . . . . . . . . . . . . .86

3.15 Built-in annotation types . . . . . . . . . . . . . . . . . . . . . .

86

3.16 Reflection support builtin types . . . . . . . . . . . . . . . . . . .

87

3.16.1kotlin.reflect.KClass. . . . . . . . . . . . . . . . . .87

3.16.2kotlin.reflect.KCallable. . . . . . . . . . . . . . . .87

3.16.3kotlin.reflect.KProperty. . . . . . . . . . . . . . . .87

3.16.4kotlin.reflect.KFunction. . . . . . . . . . . . . . . .87

4 Declarations 89

Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

4.1 Classifier declaration . . . . . . . . . . . . . . . . . . . . . . . . .

89

4.1.1 Class declaration . . . . . . . . . . . . . . . . . . . . . . .

90
Constructor declaration . . . . . . . . . . . . . . . . . . . 92
Constructor declaration scopes . . . . . . . . . . . 94
Nested and inner classifiers . . . . . . . . . . . . . . . . . 94
Inheritance delegation . . . . . . . . . . . . . . . . . . . . 96
Abstract classes . . . . . . . . . . . . . . . . . . . . . . . . 98

4.1.2 Data class declaration . . . . . . . . . . . . . . . . . . . .

98

4.1.3 Enum class declaration . . . . . . . . . . . . . . . . . . .

101

4.1.4 Annotation class declaration . . . . . . . . . . . . . . . .

103

4.1.5 Value class declaration . . . . . . . . . . . . . . . . . . . .

104

4.1.6 Interface declaration . . . . . . . . . . . . . . . . . . . . .

105
Functional interface declaration . . . . . . . . . . . . . . . 106

4.1.7 Object declaration . . . . . . . . . . . . . . . . . . . . . .

107

4.1.8 Local class declaration . . . . . . . . . . . . . . . . . . . .

108

4.1.9 Classifier initialization . . . . . . . . . . . . . . . . . . . .

108

4.1.10 Classifier declaration scopes . . . . . . . . . . . . . . . . .

110

4.2 Function declaration . . . . . . . . . . . . . . . . . . . . . . . . .

111

4.2.1 Function signature . . . . . . . . . . . . . . . . . . . . . .

112

4.2.2 Named, positional and default parameters . . . . . . . . .

113

4.2.3 Variable length parameters . . . . . . . . . . . . . . . . .

114

4.2.4 Extension function declaration . . . . . . . . . . . . . . .

115

4.2.5 Inlining . . . . . . . . . . . . . . . . . . . . . . . . . . . .

116

4.2.6 Infix functions . . . . . . . . . . . . . . . . . . . . . . . .

117

4.2.7 Local function declaration . . . . . . . . . . . . . . . . . .

118

4.2.8 Tail recursion optimization . . . . . . . . . . . . . . . . .

118

4.2.9 Function declaration scopes . . . . . . . . . . . . . . . . .

119

4.3 Property declaration . . . . . . . . . . . . . . . . . . . . . . . . .

119

4.3.1 Read-only property declaration . . . . . . . . . . . . . . .

120

4.3.2 Mutable property declaration . . . . . . . . . . . . . . . .

120

4.3.3 Local property declaration . . . . . . . . . . . . . . . . . .

121
viCONTENTS

4.3.4 Getters and setters . . . . . . . . . . . . . . . . . . . . . .

121

4.3.5 Delegated property declaration . . . . . . . . . . . . . . .

122

4.3.6 Extension property declaration . . . . . . . . . . . . . . .

126

4.3.7 Property initialization . . . . . . . . . . . . . . . . . . . .

127

4.3.8 Constant properties . . . . . . . . . . . . . . . . . . . . .

127

4.3.9 Late-initialized properties . . . . . . . . . . . . . . . . . .

128

4.3.10 Property declaration scopes . . . . . . . . . . . . . . . . .

128

4.4 Type alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

129

4.5 Declarations with type parameters . . . . . . . . . . . . . . . . .

129

4.5.1 Type parameter variance . . . . . . . . . . . . . . . . . .

130

4.5.2 Reified type parameters . . . . . . . . . . . . . . . . . . .

132

4.5.3 Underscore type arguments . . . . . . . . . . . . . . . . .

132

4.6 Declaration visibility . . . . . . . . . . . . . . . . . . . . . . . . .

133

5 Inheritance 137

5.1 Classifier type inheritance . . . . . . . . . . . . . . . . . . . . . .

137

5.1.1 Abstract classes . . . . . . . . . . . . . . . . . . . . . . . .

138

5.1.2 Sealed classes and interfaces . . . . . . . . . . . . . . . . .

138

5.1.3 Inheritance from built-in types . . . . . . . . . . . . . . .

138

5.2 Matching and subsumption of declarations . . . . . . . . . . . . .

138

5.3 Inheriting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

139

5.4 Overriding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

139

6 Scopes and identifiers 143

6.1 Linked scopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

145

6.2 Identifiers and paths . . . . . . . . . . . . . . . . . . . . . . . . .

146

6.3 Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

146

7 Statements 147

7.1 Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

147

7.1.1 Simple assignments . . . . . . . . . . . . . . . . . . . . . .

148

7.1.2 Operator assignments . . . . . . . . . . . . . . . . . . . .

148

7.1.3 Safe assignments . . . . . . . . . . . . . . . . . . . . . . .

149
quotesdbs_dbs10.pdfusesText_16