Muutke küpsiste eelistusi

Kotlin in Action [Pehme köide]

4.41/5 (1152 hinnangut Goodreads-ist)
  • Formaat: Paperback / softback, 360 pages, kõrgus x laius x paksus: 234x185x18 mm, kaal: 611 g
  • Ilmumisaeg: 03-Apr-2017
  • Kirjastus: Manning Publications
  • ISBN-10: 1617293296
  • ISBN-13: 9781617293290
Teised raamatud teemal:
  • Formaat: Paperback / softback, 360 pages, kõrgus x laius x paksus: 234x185x18 mm, kaal: 611 g
  • Ilmumisaeg: 03-Apr-2017
  • Kirjastus: Manning Publications
  • ISBN-10: 1617293296
  • ISBN-13: 9781617293290
Teised raamatud teemal:
Kotlin is a new programming language targeting the Java platform. It offers on expressiveness and safety without compromising simplicity, seamless interoperability with existing Java code, and great tooling support. Because Kotlin generates regular Java bytecode and works together with existing Java libraries and frameworks, it can be used almost everywhere where Java is used today - for server-side development, Android apps, and much more.



Kotlin in Action takes experienced Java developers from the language basics all the way through building applications to run on the JVM and Android devices. Written by core developers of Kotlin, this examplerich book begins by teaching the basic syntax of the Kotlin language. Then readers learn how to use features that let them build reusable abstractions, higher-level functions, libraries, and even entire domain specific languages. Finally, the book focuses on details of applying Kotlin in real-world projects, such as build system integration, Android support and concurrent programming.



KEY FEATURES

Hands on examples Tutorial for a new programming language Teaches how to build Android applications Written by core developers of Kotlin



AUDIENCE This book is for experienced Java developers.



ABOUT THE TECHNOLOGY Kotlin is a new programming language targeting the Java platform. It offers expressiveness and safety without compromising simplicity, seamless interoperability with existing Java code, and great tooling support.
Foreword xv
Preface xvii
Acknowledgments xix
About This Book xxi
About The Authors xxiv
About The Cover Illustration xxv
Part 1 Introducing Kotlin
1 Kotlin: what and why
3(14)
1.1 A taste of Kotlin
3(1)
1.2 Kotlin's primary traits
4(3)
Target platforms: server-side, Android, anywhere Java runs
4(1)
Statically typed
5(1)
Functional and object-oriented
6(1)
Free and open source
7(1)
1.3 Kotlin applications
7(3)
Kotlin on the server side
8(1)
Kotlin on Android
9(1)
1.4 The philosophy of Kotlin
10(3)
Pragmatic
10(1)
Concise
11(1)
Safe
12(1)
Interoperable
12(1)
1.5 Using the Kotlin tools
13(2)
Compiling Kotlin code
13(1)
Plug-in forIntellif IDEA and Android Studio
14(1)
Interactive shell
15(1)
Eclipse plug-in
15(1)
Online playground
15(1)
Java-to-Kotlin converter
15(1)
1.6 Summary
15(2)
2 Kotlin basics
17(27)
2.1 Basic elements: functions and variables
18(5)
Hello, world!
18(1)
Functions
18(2)
Variables
20(2)
Easier string formatting: string templates
22(1)
2.2 Classes and properties
23(5)
Properties
23(2)
Custom accessors
25(1)
Kotlin source code layout: directories and packages
26(2)
2.3 Representing and handling choices: enums and "when"
28(7)
Declaring enum classes
28(1)
Using "when" to deal with enum classes
29(1)
Using "when" with arbitrary objects
30(1)
Using "when" without an argument
31(1)
Smart casts: combining type checks and casts
31(2)
Refactoring: replacing "if with "when"
33(1)
Blocks as branches of "if' and "when"
34(1)
2.4 Iterating over things: "while" and "for" loops
35(4)
The "while" loop
35(1)
Iterating over numbers: ranges and progressions
36(1)
Iterating over maps
37(1)
Using "in" to check collection and range membership
38(1)
2.5 Exceptions in Kotlin
39(3)
"try", "catch", and "finally"
40(1)
"try" as an expression
41(1)
2.6 Summary
42(2)
3 Defining and calling functions
44(23)
3.1 Creating collections in Kotlin
45(1)
3.2 Making functions easier to call
46(5)
Named arguments
47(1)
Default parameter values
48(1)
Getting rid of static utility classes: top-level functions and properties
49(2)
3.3 Adding methods to other people's classes: extension functions and properties
51(6)
Imports and extension functions
53(1)
Calling extension functions from Java
53(1)
Utility functions as extensions
54(1)
No overriding for extension functions
55(1)
Extension properties
56(1)
3.4 Working with collections: varargs, infix calls, and library support
57(3)
Extending the Java Collections API
57(1)
Varargs: functions that accept an arbitrary number of arguments
58(1)
Working with pairs: infix calls and destructuring declarations
59(1)
3.5 Working with strings and regular expressions
60(4)
Splitting strings
60(1)
Regular expressions and triple-quoted strings
61(1)
Multiline triple-quoted strings
62(2)
3.6 Making your code tidy: local functions and extensions
64(2)
3.7 Summary
66(1)
4 Classes, objects, and interfaces
67(36)
4.1 Defining class hierarchies
68(10)
Interfaces in Kotlin
68(2)
Open, final, and abstract modifiers: final by default
70(3)
^ Visibility modifiers: public by default
73(2)
Inner and nested classes: nested by default
75(2)
Sealed classes: defining restricted class hierarchies
77(1)
4.2 Declaring a class with nontrivial constructors or properties
78(9)
Initializing classes: primary constructor and initializes blocks
79(2)
Secondary constructors: initializing the superclass in different ways
81(2)
Implementing properties declared in interfaces
83(2)
Accessing a backing field from a getter or setter
85(1)
Changing accessor visibility
86(1)
4.3 Compiler-generated methods: data classes and class delegation
87(6)
Universal object methods
87(2)
Data classes: autogenerated implementations of universal methods
89(2)
Class delegation: using the "by" keyword
91(2)
4.4 The "object" keyword: declaring a class and creating an instance, combined
93(8)
Object declarations: singletons made easy
93(3)
Companion objects: a place for factory methods and static members
96(2)
Companion objects as regular objects
98(2)
Object expressions: anonymous inner classes rephrased
100(1)
4.5 Summary
101(2)
5 Programming with lambdas
103(30)
5.1 Lambda expressions and member references
104(9)
Introduction to lambdas: blocks of code as function parameters
104(1)
Lambdas and collections
105(1)
Syntax for lambda expressions
106(3)
Accessing variables in scope
109(2)
Member references
111(2)
5.2 Functional APIs for collections
113(5)
Essentials: filter and map
113(2)
"all", "any", "count", and "find": applying a predicate to a collection
115(2)
groupBy: converting a list to a map of groups
117(1)
flatMap and flatten: processing elements in nested collections
117(1)
5.3 Lazy collection operations: sequences
118(5)
Executing sequence operations: intermediate and terminal operations
120(2)
Creating sequences
122(1)
5.4 Using Java functional interfaces
123(5)
Passing a lambda as a parameter to a Java method
124(2)
SAM constructors: explicit conversion of lambdas to functional interfaces
126(2)
5.5 Lambdas with receivers: "with" and "apply"
128(3)
The "with" function
128(2)
The "apply" function
130(1)
5.6 Summary
131(2)
6 The Kotlin type system
133(38)
6.1 Nullability
133(20)
Nullable types
134(2)
The meaning of types
136(1)
Safe call operator: "?."
137(2)
Elvis operator: "?:"
139(1)
Safe casts: "as?"
140(1)
Not-null assertions: "!!"
141(2)
The "let" function
143(2)
Late-initialized properties
145(1)
Extensions for nullable types
146(2)
Nullability of type parameters
148(1)
Nullability and Java
149(4)
6.2 Primitive and other basic types
153(6)
Primitive types: Int, Boolean, and more
153(1)
Nullable primitive types: Int?, Boolean?, and more
154(1)
Number conversions
155(2)
"Any" and "Any?": the root types
157(1)
The Unit type: Kotlin's "void"
157(1)
The Nothing type: "This function never returns"
158(1)
6.3 Collections and arrays
159(11)
Nullability and collections
159(2)
Read-only and mutable collections
161(2)
Kotlin collections and Java
163(2)
Collections as platform types
165(2)
Arrays of objects and primitive types
167(3)
6.4 Summary
170(1)
Part 2 Embracing Kotlin 171(142)
7 Operator overloading and other conventions
173(27)
7.1 Overloading arithmetic operators
174(6)
Overloading binary arithmetic operations
174(3)
Overloading compound assignment operators
177(1)
Overloading unary operators
178(2)
7.2 Overloading comparison operators
180(2)
Equality operators: "equals"
180(1)
Ordering operators: compareTo
181(1)
7.3 Conventions used for collections and ranges
182(5)
Accessing elements by index: "get" and "set"
182(2)
The "in" convention
184(1)
The rangeTo convention
185(1)
The "iterator" convention for the "for" loop
186(1)
7.4 Destructuring declarations and component functions
187(2)
Destructuring declarations and loops
188(1)
7.5 Reusing property accessor logic: delegated properties
189(10)
Delegated properties: the basics
189(1)
Using delegated properties: lazy initialization and "by lazy( )"
190(2)
Implementing delegated properties
192(3)
Delegated-property translation rules
195(1)
Storing property values in a map
196(1)
Delegated properties in frameworks
197(2)
7.6 Summary
199(1)
8 Higher-order functions: lambdas as parameters and return values
200(23)
8.1 Declaring higher-order functions
201(10)
Function types
201(1)
Calling functions passed as arguments
202(2)
Using function types from Java
204(1)
Default and null values for parameters with function types
205(2)
Returning functions from functions
207(2)
Removing duplication through lambdas
209(2)
8.2 Inline functions: removing the overhead of lambdas
211(6)
How inlining works
211(2)
Restrictions on inline functions
213(1)
Inlining collection operations
214(1)
Deciding when to declare functions as inline
215(1)
Using in lined lambdas for resource management
216(1)
8.3 Control flow in higher-order functions
217(4)
Return statements in lambdas: return from an enclosing function
217(1)
Returning from lambdas: return with a label
218(2)
Anonymous functions: local returns by default
220(1)
8.4 Summary
221(2)
9 Generics
223(31)
9.1 Generic type parameters
224(6)
Generic functions and properties
224(2)
Declaring generic classes
226(1)
Type parameter constraints
227(2)
Making type parameters non-null
229(1)
9.2 Generics at runtime: erased and reified type parameters
230(7)
Generics at runtime: type checks and casts
230(3)
Declaring functions with reified type parameters
233(2)
Replacing class references with reified type parameters
235(1)
Restrictions on reified type parameters
236(1)
9.3 Variance: generics and subtyping
237(15)
Why variance exists: passing an argument to a function
237(1)
Classes, types, and subtypes
238(2)
Covariance: preserved subtyping relation
240(4)
Contravariance: reversed subtyping relation
244(2)
Use-site variance: specifying variance for type occurrences
246(2)
Star projection: using instead of a type argument
248(4)
9.4 Summary
252(2)
10 Annotations and reflection
254(28)
10.1 Declaring and applying annotations
255(9)
Applying annotations
255(1)
Annotation targets
256(2)
Using annotations to customize JSON serialization
258(2)
Declaring annotations
260(1)
Meta-annotations: controlling how an annotation is processed
261(1)
Classes as annotation parameters
262(1)
Generic classes as annotation parameters
263(1)
10.2 Reflection: introspecting Kotlin objects at runtime
264(17)
The Kotlin reflection API: KClass, KCallable, KFunction, and KProperty
265(3)
Implementing object serialization using reflection
268(2)
Customizing serialization with annotations
270(3)
JSON parsing and object deserialization
273(4)
Final deserialization step: callBy() and creating objects using reflection
277(4)
10.3 Summary
281(1)
11 DSL construction
282(31)
11.1 From APIs to DSLs
283(5)
The concept of domain-specific languages
284(1)
Internal DSLs
285(1)
Structure of DSLs
286(1)
Building HTML with an internal DSL
287(1)
11.2 Building structured APIs: lambdas with receivers in DSLs
288(11)
Lambdas with receivers and extension function types
288(4)
Using lambdas with receivers in HTML builders
292(4)
Kotlin builders: enabling abstraction and reuse
296(3)
11.3 More flexible block nesting with the "invoke" convention
299(4)
The "invoke" convention: objects callable as functions
299(1)
The "invoke" convention and functional types
300(1)
The "invoke" convention in DSLs: declaring dependencies in Cradle
301(2)
11.4 Kotlin DSLs in practice
303(7)
Chaining infix calls: "should" in test frameworks
303(2)
Defining extensions on primitive types: handling dates
305(1)
Member extension functions: internal DSL for SQL
306(3)
Anko: creating Android UIs dynamically
309(1)
11.5 Summary
310(3)
Appendix A Building Kotlin projects 313(4)
Appendix B Documenting Kotlin code 317(3)
Appendix C The Kotlin ecosystem 320(3)
Index 323