售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
About Packt
Why subscribe?
Packt.com
Contributors
About the authors
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Section 1: Fundamental Concepts in Kotlin
Getting Started with Kotlin
Technical requirements
Using the command line to compile and run Kotlin code
Kotlin runtime
The REPL
Kotlin for scripting
Kotlin with Gradle
Kotlin with Maven
IntelliJ and Kotlin
Eclipse and Kotlin
Mixing Kotlin and Java in a project
Summary
Kotlin Basics
val and var
Type inference
Basic types in Kotlin
Numbers
Unsigned integers
Booleans
Chars
Strings
Arrays
Comments
Packages
Imports
Wildcard imports
Import renaming
String templates
Ranges
Loops
Exception handling
Instantiating classes
Referential equality and structural equality
This expression
Scope
Visibility modifiers
Private
Protected
Internal
Control flow as expressions
The null syntax
Smart casts
Explicit casting
The when expression
When (value)
The when without argument
Function return
Type hierarchy
Code contracts
Contracts API
Contracts on a function return value
Contracts on method invocation
Limitations
Summary
Object-Oriented Programming in Kotlin
Classes
Access levels
Nested classes
Data classes
Inline classes
Enum classes
Static methods and companion objects
Interfaces
Inheritance
Visibility modifiers
Abstract classes
Interface or abstract classes
Polymorphism
Overriding rules
Inheritance versus composition
Class delegation
Sealed classes
Summary
Section 2: Practical Concepts in Kotlin
Functions in Kotlin
Defining functions
Single expression functions
Member functions
Local functions
Top-level functions
Named parameters
Default parameters
Extension functions
Extension function precedence
Extension functions on null values
Member extension functions
Overriding member extension functions
Companion object extensions
Multiple return values
Infix functions
Operators
Operator overloading
Basic operators
in/contains
Get/set
Invoke
Comparison
Assignment
Java interop
Function literals
Tail recursive functions
Varargs
Spread operator
Standard library functions
Apply
Let
With
Run
Lazy
Use
Repeat
Require/assert/check
Generic functions
Pure functions
Java from Kotlin
Getters and setters
Single abstract methods
Escaping Kotlin identifiers
Java void methods
Kotlin from Java
Top-level functions
Default parameters
Object and static methods
Erasure naming
Checked exceptions
Summary
Higher-Order Functions and Functional Programming
Higher-order functions
Returning a function
Assigning a function
Closures
Anonymous functions
Function references
Top-level function references
Member and extension function references
Bound references
Function-literal receivers
Functions in the JVM
Bytecode
Function composition
Inline functions
Noinline
Currying and partial application
Currying in action
Adding currying support
Memoization
Implementing memoization
Type alias
Either
Fold
Projection
Further projection functions
Custom DSLs
Infix functions as keywords
Using function receivers in a DSL
Validation and error accumulation
Summary
Properties
Why use properties?
Overriding getters and setters
Visibility
Late initialization
Delegated properties
Lazy initializations
Lateinit versus lazy
Observables
A non-null property delegate
Properties or methods?
Summary
Null Safety, Reflection, and Annotations
Nullable types
Smart cast
Safe null access
Force operator
Elvis operator
Safe casting
Optional
Creating and returning an Optional
Using an Optional
Reflection
KClass
Instantiation using reflection
Constructors
Instantiation with callBy
Objects and companions
Useful KClass properties
Reflective functions and properties
Invoking a function reflectively
Declared and undeclared
Annotations
Annotation parameters
Standard annotations
@JvmName
@JvmStatic
@Throws
@JvmOverloads
Runtime annotation discovery
Summary
Generics
Parameterized functions
Parameterized types
Bounded polymorphism
Upper bounds
Multiple bounds
Type variance
Invariance
Covariance
Covariant return
Contravariance
Variance overview
Nothing type
Type projection
Type erasure
Type reification
Recursive type bounds
Algebraic data types
Summary
Data Classes
Introduction to data classes
Automatic creation of getters and setters
The copy method
toString out of the box
The hashCode and equals methods generated for you
Destructed declarations
Destructing types
Data class definition rules
Limitations
Summary
Collections
Class hierarchy
Arrays
Lists
Maps
Sets
Read-only views
Indexed access
Sequences
Summary
Testing in Kotlin
Getting started
Choosing a spec
Matchers
String matchers
Collection matchers
Floating point matchers
Expecting exceptions
Combining matchers
Custom matchers
Inspectors
Interceptors
The test case interceptor
The spec interceptor
Project config
Property testing
Specifying a generator
A custom generator
Table-driven testing
Testing non-deterministic code
Tags, conditions, and config
Config
Conditions
Tags
One instance
Resources
Summary
Microservices with Kotlin
Definition
Drawbacks
Why microservices?
Lagom
Defining services
Implementing a Lagom service
Summary
Section 3: Advanced Concepts in Kotlin
Concurrency
Threads
Blocking
Creating a thread
Stopping a thread
Thread interrupts
CPU-bound versus I/O-bound
Deadlocks and livelocks
The Dining Philosophers Problem
Executors
Race conditions
Monitors
Locks
Read-write locks
Semaphores
he bounded buffer problem
Concurrent collections
ConcurrentHashMap
A blocking queue
Atomic variables
CountDownLatch
CyclicBarrier
Non-blocking I/O and asynchronous programming
Futures
Summary
Coroutines
Suspending functions
Coroutine builders
Launch builder
runBlocking Builder
Structured concurrency
Nested coroutines
Parent-child relationship
Jobs
Cancellation
Join
Job state
Context and scope
Global scope
Cancellation and failure
Cancellation or failure in a parent
Failure in a child coroutine
Supervisor scope
Async
Coroutine dispatchers
Dispatcher inheritance
Wrapping Java executors
With context
Error handling
Summary
Application of Coroutines
Channels
Rendezvous channels
Closing a channel
Producers
Conflated channels
Ticker channels
select expression
Using select for channels
Using select for deferred
Debugging coroutines
Coroutines in action
Concurrent HTTP requests
Blocking IO with coroutines
Using callbacks with coroutines
Summary
Kotlin Serialization
Setup
Json serialization and deserialization
How it works
Protobuf serialization and deserialization
Annotations
Rules
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜