Learn how to use destructuring in Kotlin. Using destructuring with data classes is automatic, but adding it to regular classes isn't difficult either.
- [Instructor] Destructuring is a way for us to pull…just the variables we want from a more complicated object.…Let's take a look at the position data class…back in demo.main again.…So we'll go to demo.main.…Because it is a data class, Kotlin includes the mechanisms…of destructuring.…So what we can do is we can say val, xPosition, yPosition,…and then say that it equals p1.…
And what this is going to do is it's going to create two variables…for us, xPosition and yPosition, and pull their values…off of the data class p1.…And so, if we print those out...…And we say yPosition equals dollar sign yPosition...…
And we go ahead and run this.…And here is our data.…In the code, we are creating two new variables,…xPosition and yPosition.…We are setting them based on the properties…of the data class.…Kotlin gets the value for each variable based on the order…that the properties were created in their constructor.…So the first property gets assigned to the first variable,…the second property gets assigned to the second variable,…
- Kotlin as a better Java
- Setting up a Kotlin programming environment
- Val vs. var
- Understanding basic Kotlin programming concepts
- Object-oriented programming
- Using Java from Kotlin
- Using Kotlin from Java
- Annotations, reflection, and DSL construction
- Functional programming in Kotlin
Skill Level Advanced
1. Kotlin as a Better Java
Why a new JVM language?1m 35s
2. Get Started with Kotlin
3. Basic Kotlin Programming
4. Object-Oriented Programming
5. Java Interop
6. Advanced Kotlin Features
7. Functional Programming in Kotlin
- 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.