From the course: Transitioning from Java to Kotlin
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Java and Kotlin interop
From the course: Transitioning from Java to Kotlin
Java and Kotlin interop
- [Instructor] Let's take a look at a couple of the ways in which Kotlin to Java interop works and may be customized for a better developer experience. First, let's open ProductService.java. In the insert method, notice how we call a number of getters on our instance of product. However, if we open up our Product class, once again, we'll notice that we don't actually have any getters or setters defined on our data class. How then does this code compile without any errors? The compiler generates getters and setters for immutable properties on a Kotlin class. That's why from ProductService.java, we can call getName. And in fact, if we click into the implementation of getName, we're taken directly to that public property on the Product class. And if we go over to AdminController, we'll notice here that in our log statement, that we are accessing the name property directly. This Kotlin usage is leveraging what's known as…
Contents
-
-
-
-
-
-
(Locked)
Exploring an existing server-side application8m 24s
-
(Locked)
Adding Kotlin to an existing project7m 24s
-
(Locked)
Migrating Java code to Kotlin4m 37s
-
(Locked)
Handling platform types6m 31s
-
(Locked)
Leveraging Kotlin language features14m 56s
-
(Locked)
Java and Kotlin interop3m 53s
-
(Locked)
Challenge: Migrate the project to Kotlin32s
-
(Locked)
Solution: Migrate the project to Kotlin8m 31s
-
(Locked)
-
-