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

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