A constant is a value that never changes. In Kotlin, you can declare an immutable variable anywhere with the keyword val, but that's just the beginning of the story. Learn how to create real constants, and how to make them globally available to your entire application with having to know where they're defined.
- [Instructor] When you move from Java to Kotlin…you'll find that constants, values that never changed,…are handled differently.…First of all Kotlin has a const key word…which Java lacks, so you can officially label a value…as a constant as opposed to just being another variable.…But they'll also placed in a specific location…within classes, and you can also…create global constants.…Valuables that are available throughout an application.…When I converted this application from Java to Kotlin…I got something called a companion object.…
And a field that I had declared as static…and final in Java, became a member of this companion object.…This is because Kotlin doesn't have a concept…of static class members.…In order to address a value from a class declaration…as opposed from a class instance, you put it inside…a companion object like this.…Now I'm going to add another value here,…and I'll use the same syntax, private val,…and I'll set this constant with a name of THE_ANSWER.…
And I'll give it an integer value of 42.…
Skill Level Intermediate
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.
Android App Development: Communicating with the Userwith Joe Marini1h 12m Intermediate
Building Android Apps with Cloud Serviceswith Albert Lo2h 37m Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
New This Week:
1. Android Development Tips Weekly
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.