<p><span>You know how to use Kotlin, but do you know the advanced features? What are the consequences of using variance modifiers? What limitations do they introduce, and how can these be overcome? How does property delegation work? How to use reflection? How to implement a KSP or an annotation proc
Advanced Kotlin (Kotlin for Developers)
β Scribed by Marcin Moskala
- Publisher
- 978-83-966847-4-5
- Year
- 2023
- Tongue
- English
- Leaves
- 372
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
You know how to use Kotlin, but do you know the advanced features? What are the consequences of using variance modifiers? What limitations do they introduce, and how can these be overcome? How does property delegation work? How to use reflection? How to implement a KSP or an annotation processor? How is a Kotlin Compiler Plugin implemented? If you want to know the answers to these questions, this book is for you.
About the book
This book focuses on the advanced aspects of Kotlin's development. These are often features and tools that developers use daily, even though they donβt know exactly how they work. This book explains them and gives you the knowledge to use these features in your projects.
Who this book is for
This book is for developers with Kotlin experience who want to learn about its advanced features. Readers are expected to have experience in Kotlin development. All the required knowledge can be discovered in the books Kotlin Essentials and Functional Kotlin.
What is covered
This book focuses on advanced Kotlin features, including:
- Generic variance modifiers
- Interface and property delegation
- Kotlin Contracts
- Kotlin and Java interoperability
- Multiplatform development
- Using Kotlin/JS
- Kotlin reflection
- Annotation Processor
- Kotlin Symbol Processor
- Kotlin Compiler Plugins
- Static Analysis with custom rules
β¦ Table of Contents
Table of Contents
Introduction
Who is this book for?
That will be covered?
The structure of the book
The Kotlin for Developers series
Conventions
Code conventions
Acknowledgments
Generic variance modifiers
List variance
Consumer variance
Function types
The Covariant Nothing Object
The Covariant Nothing Class
Variance modifier limitations
UnsafeVariance annotation
Variance modifier positions
Star projection
Summary
Exercise: Generic types usage
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 getValue and setValue parameters
Implementing a custom property delegate
Provide a delegate
Property delegates in Kotlin stdlib
The notNull delegate
Exercise: Lateinit delegate
The lazy delegate
Exercise: Blog Post Properties
The observable delegate
The vetoable delegate
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
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
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
Kotlin Symbol Processing
Your first KSP processor
Testing KSP
Dependencies and incremental processing
Multiple rounds processing
Using KSP on multiplatform projects
Summary
Exercise: Kotlin Symbol Processing
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
Ending
Exercise solutions
π SIMILAR VOLUMES
<p><span>Kotlin coroutines revolutionized JVM development, especially on Android and the backend. They let us easily make efficient and reliable multithreading. Its cutting-edge design and features are suited ideally for modern use cases. In this book, we will explore Kotlin coroutines - both built-
<p><span>Kotlin coroutines revolutionized JVM development, especially on Android and the backend. They let us easily make efficient and reliable multithreading. Its cutting-edge design and features are suited ideally for modern use cases. In this book, we will explore Kotlin coroutines - both built-
Unlocking Kotlin: A Comprehensive Guide to Android Development for Tech Enthusiasts and Beginners "Unlocking Kotlin," your go-to guide for mastering the powerful Kotlin programming language. Whether you're a seasoned tech enthusiast or a curious beginner, this comprehensive e-book is tailored to
Learn how to create your own apps for Android, in the Kotlin programming language! Through the course of this book, you will be taught from the ground-up how to create and develop your own Android apps in the Kotlin language, which has been given first-class status by Google. You will be given detai