Introduction
- Who is this book for?
- The structure of this book
- That will be covered?
- The Kotlin for Developers series
- Conventions
- Code conventions
- Exercises and solutions
- Acknowledgments
Part 1: Advanced Kotlin features
Generic variance modifiers
- List variance
- Consumer variance
- Function types
- Exercise: Usage of generic types
- The Covariant Nothing Object
- The Covariant Nothing Class
- Variance modifier limitations
- UnsafeVariance annotation
- Variance modifier positions
- Star projection
- Summary
- Exercise: Generic Response
- Exercise: Generic Consumer
Interface delegation
- The delegation pattern
- Delegation and inheritance
- Kotlin interface delegation support
- Wrapper classes
- The decorator pattern
- Intersection types
- Limitations
- Conflicting elements from parents
- Summary
- Exercise: ApplicationScope
Property delegation
- How property delegation works
- Other
getValueandsetValueparameters - Implementing a custom property delegate
- Provide a delegate
- Property delegates in Kotlin stdlib
- The
notNulldelegate - Exercise: Lateinit delegate
- The
lazydelegate - Exercise: Blog Post Properties
- The
observabledelegate - The
vetoabledelegate - A map as a delegate
- Review of how variables work
- Summary
- Exercise: Mutable lazy delegate
Kotlin Contracts
- The meaning of a contract
- How many times do we invoke a function from an argument?
- Implications of the fact that a function has returned a value
- Using contracts in practice
- Summary
- Exercise: Coroutine time measurement
Part 2: Kotlin on different platforms
Java interoperability
- Nullable types
- Kotlin type mapping
- JVM primitives
- Collection types
- Annotation targets
- Static elements
- JvmField
- Using Java accessors in Kotlin
- JvmName
- JvmMultifileClass
- JvmOverloads
- Unit
- Function types and function interfaces
- Tricky names
- Throws
- JvmRecord
- Summary
- Exercise: Adjust Kotlin for Java usage
Using Kotlin Multiplatform
- Multiplatform module configuration
- Expect and actual elements
- Possibilities
- Multiplatform libraries
- A multiplatform mobile application
- Summary
- Exercise: Multiplatform LocalDateTime
JavaScript interoperability
- Setting up a project
- Using libraries available for Kotlin/JS
- Using Kotlin/JS
- Building and linking a package
- Distributing a package to npm
- Exposing objects
- Exposing Flow and StateFlow
- Adding npm dependencies
- Frameworks and libraries for Kotlin/JS
- JavaScript and Kotlin/JS limitations
- Summary
- Exercise: Migrating a Kotlin/JVM project to KMP
Part 3: Metaprogramming
Reflection
- Hierarchy of classes
- Function references
- Parameter references
- Property references
- Class reference
- Serialization example
- Referencing types
- Type reflection example: Random value
- Kotlin and Java reflection
- Breaking encapsulation
- Summary
- Exercise: Function caller
- Exercise: Object serialization to JSON
- Exercise: Object serialization to XML
- Exercise: DSL-based dependency injection library
Annotation processing
- Your first annotation processor
- Hiding generated classes
- Summary
- Exercise: Annotation Processing execution measurement wrapper
Kotlin Symbol Processing
- Your first KSP processor
- Testing KSP
- Dependencies and incremental processing
- Multiple rounds processing
- Using KSP on multiplatform projects
- Summary
- Exercise: KSP execution measurement wrapper
Kotlin Compiler Plugins
- Compiler frontend and backend
- Compiler extensions
- Popular compiler plugins
- Making all classes open
- Changing a type
- Generate function wrappers
- Example plugin implementations
- Summary
Static Code Analysers
- What are Static Analysers?
- Types of analysers
- Kotlin Code Analysers
- Setting up detekt
- Writing your first detekt Rule
- Conclusion
