Crazy Kotlin handouts

Links: https://pan.baidu.com/s/1lKMZxniTpCGdnUNunGfuoA

Extraction code: jqqa

Here Insert Picture Description

Chapter 1 Kotlin language and development environment 1

1.1 Kotlin language Introduction 2

1.1.1 the service side of Kotlin 2

1.1.2 Kotlin develop Android applications 2

1.1.3 Kotlin for JavaScript 3

1.2 using the command-line compiler, run Kotlin 3

1.2.1 download and install the SDK 3 Kotlin

1.2.2 The first Kotlin program 4

1.2.3 compile and run the program Kotlin 5

IntelliJ IDEA 1.3 using to build, run Kotlin 6

1.4 using Eclipse to compile, run Kotlin 8

1.5 Summary 10

Chapter 2 Kotlin basis of Type 11

2.1 Note 12

2.1.1 single-line and multiline comments 12

2.1.2 Documentation Comments 12

2.2 Variable 14

2.2.1 delimiter 15

2.2.2 Identifier Rule 16

2.2.3 Kotlin keywords 17

2.2.4 declare variables 19

2.3 Integer 21

2.4 Float 23

2.5 character 24

2.6 numeric type conversion between 25

2.6.1 integer conversion between 25

2.6.2 conversion between floating point and integer 28

2.6.3 expression type of automatic upgrade 28

2.7 Boolean type 30

2.8 null security 31

2.8.1 non-empty types and nullable type 31

2.8.2 After 32 first determines using

2.8.3 Safety calls 32

2.8.4 Elvis operation 33

2.8.5 Forced call 34

2.9 String 34

2.9.1 String Type 34

2.9.2 String template 35

Method 2.9.3 Kotlin string 36

2.10 Alias ​​Type 37

2.11 Summary 38

Chapter 3 Operators and Expressions 39

Java 3.1 and the same operator 40

3.1.1 Single present infix operators 40

3.1.2 from Canada and decrement operators 41

3.1.3 Arithmetic operators eyes 41

And 3.1.4 in! Operators in 42

3.1.5 index access operator 43

3.1.6 call operator 43

3.1.7 generalized assignment operator 44

3.1.8 equal inequality operators 44

45 3.1.9 Comparison operators

3.2 Operators 46

3.3 operator section 48

3.3.1 operator closed interval 48

3.3.2 operator half-open interval 49

3.3.3 reverse section 49

3.3.4 step interval 49

50 3.4 operator overloading

3.4.1 Single overload current infix operators 50

3.4.2 overload from Canada and decrement operators 51

3.4.3 binocular overloaded arithmetic operators 51

3.5 Summary 52

Chapter 4 Process Control 53

Sequence Structure 54 4.1

4.2 54 branched structure

4.2.1 if the branch 54

4.2.2 if the expression 58

4.2.3 when branch statement 58

4.2.4 when the expression 61

4.2.5 when branching range 62

4.2.6 when branching type 62

4.2.7 when a conditional branch 63

4.3 loop structure 63

4.3.1 while loop 64

4.3.2 do while loop 65

4.3.3 for-in loop 66

4.3.4 nested loops 66

68 4.4 Control loop structure

4.4.1 Using break the loop ends 68

4.4.2 Use continue to ignore this cycle

The remaining 69 statements

4.4.3 return the end of the method 70

4.5 Summary 71

Chapter 5, and a set of arrays 72

5.1 Array 73

5.1.1 Creating an array 73

5.1.2 Using arrays 75

5.1.3 for-in loop through the array 76

5.1.4 Using the array index 76

5.1.5 array 77 common method

5.1.6 multidimensional arrays 80

Example 82 5.1.7 Application of the array

5.2 Kotlin Collections Overview 85

5.3 Set 88 collection

5.3.1 statement and create a set of 88 Set

5.3.2 Set method 90

5.3.3 traversal Set 91

5.3.4 Variable Set 92

5.4 List collection 93

5.4.1 statement and create a collection of 93 List

5.4.2 List method 94 using

5.4.3 Variable List 95

5.5 Map collection 95

5.5.1 statement and create a collection of 95 Map

5.5.2 Map method 97

5.5.3 traverse Map 98

5.5.4 Variable Map 98

5.6 Summary 99

Chapter 6 Function and Lambda expressions 100

6.1 function entry 101

6.1.1 Defining and calling functions 101

6.1.2 Unit 102 and the function returns a value

6.1.3 recursive function 103

6.1.4 Single expression functions 104

Shape function parameters 105 6.2

6.2.1 named parameter 105

6.2.2 Default parameter 106

6.2.3 tail recursive function 108

6.2.4 variable number of parameter 109

6.3 function overloading 110

6.4 local function 111

6.5 112 higher-order functions

6.5.1 Use function type 112

6.5.2 Use as a function of the type of the parameter type 113

6.5.3 Use function type as the return value type 114

6.6 local function and Lambda 115

6.6.1 Review local function 116

6.6.2 Lambda expressions instead of a local function 116

6.6.3 Lambda expressions out of 117

6.7 Lambda Expressions 117

6.7.1 Lambda expressions call 118

6.7.2 using context type inference 118

6.7.3 abbreviation participants name 119

6.7.4 Lambda expressions calling convention 120

6.7.5 variable number of parameters and the parameter Lambda 120

6.8 anonymous function 121

Usage of 121 6.8.1 anonymous function

6.8.2 Lambda expressions and anonymous functions

The return 122

6.9 capturing context variables and constants 123

The inline function 125 6.10

6.10.1 provided with associated functions 125

6.10.2 partial ban inline 126

6.10.3 non-local returns 127

6.11 Summary 128

Chapter 7, object-oriented (on) 129

7.1 classes and objects 130

7.1.1 the definition of class 130

7.1.2 object 132 generated and used

this 7.1.3 references to objects 133

7.2 Detailed Method 136

7.2.1 Function Relationship method 136

7.2.2 infix notation 137

7.2.3 componentN deconstruction method 138

7.2.4 a plurality of data classes and return values ​​of functions 140

7.2.5 deconstruction of 141 in Lambda expressions

7.3 attributes field 142 and

7.3.1 write and read-only attributes properties 142

7.3.2 custom getter and setter 144

7.3.3 behind the field 147

7.3.4 Behind the property 148

7.3.5 Delay initialization properties 149

7.3.6 with the attribute 150

7.4 hiding and encapsulation 151

7.4.1 packages and the leader packet 151

The default 7.4.2 Kotlin import 153

7.4.3 access specifier 153

7.5 depth constructor 155

7.5.1 primary configuration and initialization block 156

7.5.2 tectonic and overloaded constructor 158

7.5.3 master declaration attribute constructor 161

7.6 class inheritance 161

7.6.1 inheritance syntax 161

7.6.2 Method override the parent class 164

7.6.3 override the parent class attribute 166

7.6.4 super defined 167

7.6.5 forced to rewrite 168

More than 7.7 state 169

7.7.1 polymorphism 169

7.7.2 using exam type is 170

7.7.3 Transformation using as operator 172

7.8 Summary 174

Chapter 8 Object-Oriented (at) 175

8.1 extension 176

8.1.1 Extension Method 176

8.1.2 implementation of an extension mechanism 179

8.1.3 Method nullable type extension 182

8.1.4 Extended Attributes 182

8.1.5 to define extensions 183 members

Anonymous functions 8.1.6 with 184 recipients

8.1.7 When using extension 186

8.2 final and open modifiers 187

8.2.1 executable "macro substitution" Constant 187

8.2.2 final attribute 188

8.2.3 final method 189

8.2.4 final class 190

8.2.5 immutable class 190

8.3 abstract class 192

8.3.1 abstract and abstract classes 192 members

8.3.2 Role abstract class 195

8.3.3 sealed class 196

8.4 Interface 198

198 8.4.1 Interface definitions

8.4.2 Interface inheritance 199

8.4.3 Interface 200

8.4.4 abstract classes and interfaces 202

8.5 nested class and inner class 202

8.5.1 Internal class 204

8.5.2 Nested Class 207

8.5.3 Internal class 209 outside of the outer class

8.5.4 Class 209 outside of the outer nested class

8.5.5 partially nested class 210

8.5.6 anonymous inner class 211

8.6 Object expressions and object declarations 212

8.6.1 object expression 212

8.6.2 Singleton Pattern object declaration and 215

8.6.3 companion objects and static member 217

8.6.4 companion object extension 218

8.7 enumeration class 219

8.7.1 enumeration class entry 219

8.7.2 enumeration class attributes, methods, and constructors 221

8.7.3 enumeration class interface 222 to achieve

8.7.4 Abstract enumeration class contains abstract methods 222

8.8 class commissioned and commissioned 223 properties

8.8.1 delegate class 224

8.8.2 Properties commissioned 225

8.8.3 Delay attribute 227

8.8.4 attribute monitor 228

8.8.5 Use Map 230 stores attribute values

8.8.6 commissioned local attributes 231

8.8.7 factory commissioned 233

8.9 Summary 234

Chapter 9 Exception Handling 236

Exception handling mechanism 237 9.1

9.1.1 use try ... catch to catch exceptions 237

9.1.2 Exception class inheritance system 240

9.1.3 access exception information 242

9.1.4 Exception handling nested 243

9.1.5 try statement is an expression 243

9.2 Use throw thrown 243

9.2.1 thrown 243

9.2.2 custom exception class 244

9.2.3 catch and throw while using 245

9.2.4 Exception chaining 246

9.2.5 throw statement is an expression 247

9.3 abnormal tracking stack 248

9.4 Summary 250

Chapter 10 Generic 251

252 10.1 generic entry

10.1.1 generic interface definitions, class 252

10.1.2 subclass from the generic class 253

10.2 254 type variable

10.2.1 require generic type variable 254

10.2.2 type variable declaration at 256

10.2.3 using the variable type: Type Projection 258

10.2.4 asterisk projection 260

261 10.3 generic function

261 10.3.1 Use of generic functions

10.3.2 specific parameter types 262

10.4 parameter set type of the upper limit 263

10.5 Summary 264

Chapter 11 Notes 266

11.1 Kotlin annotation entry 267

11.1.1 defined Note 267

11.1.2 annotation and configuration properties 268

11.2 yuan notes 270

11.2.1 Use @Retention 270

11.2.2 Use @Target 271

11.2.3 Use @MustBeDocumented 272

11.2.4 numerals may be repeated using @Repeatable annotation 273

273 11.3 Use annotations

11.3.1 extract annotation information 273

11.3.2 Example 274 using annotations

11.4 Java compatibility notes and Kotlin 279

11.4.1 specify the role of the target 279 notes

11.4.2 use Java annotations 281

11.5 Summary 282

Chapter 12 Kotlin and call each other Java 283

12.1 Kotlin call Java 284

12.1.1 Properties 284

12.1.2 void and called members to call 285 keywords

12.1.3 Kotlin has been mapped type 286

12.1.4 Kotlin conversion of Java generics 287

12.1.5 Java array of processing 287

12.1.6 The method of calling a variable number of arguments 288

12.1.7 checked anomaly 289

12.1.8 Object processing 289

12.1.9 access static members 290

12.1.10 SAM conversion 290

12.1.11 in use JNI 291 in Kotlin

12.2 Java call Kotlin 291

12.2.1 Properties 291

12.2.2 package-level functions 292

12.2.3 instance variables 294

12.2.4 class variables 294

12.2.5 class methods 296

12.2.6 correspondence relationship between access specifier 297

12.2.7 get KClass 298

12.2.8 Use @JvmName resolve conflicts signature 298

12.2.9 generation heavy-duty 299

12.2.10 checked anomaly 300

12.2.11 generic type variable 300

12.3 Kotlin reflection 302

302 12.3.1 Class Reference

12.3.2 obtain class information from KClass 303

12.3.3 create an object 306

12.3.4 reference constructor 306

12.3.5 call the method 307

12.3.6 function reference 308

12.3.7 accessing the property value 309

12.3.8 property reference 311

12.3.9 binding method and property references 313

12.4 Summary 313 [1]

Guess you like

Origin blog.csdn.net/u014211007/article/details/93733716