A companion object is similar in syntax to an inner class because we declare it inside a regular class, but note we refer to it as an object, not a class. This implies it is in itself an instance as opposed to a blueprint for an instance. This is exactly what it is. When we declare a companion object inside a class, its properties and functions are shared by all instances of the regular class. It is perfect when we want a bunch of regular classes to share one set of related data. We will see a companion object in action in the next app, and also in the Age database app in the penultimate chapter.
- Tech Categories
- Best Sellers
- New Releases
- Books
- Videos
- Audiobooks
Tech Categories Popular Audiobooks
- Articles
- Newsletters
- Free Learning
You're reading from Android Programming with Kotlin for Beginners
Product typeBook
Published inApr 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789615401
Edition1st Edition
Languages
Tools
Concepts
Author (1)
John Horton
John Horton
John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton
The rest of the page is locked
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $19.99/month. Cancel anytime
You have been reading a chapter from
Android Programming with Kotlin for BeginnersPublished in: Apr 2019Publisher: PacktISBN-13: 9781789615401
© 2019 Packt Publishing Limited All Rights Reserved
Author (1)
John Horton
John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton