Add the following dependency to the dependencies
section of /app/build.gradle.kts
:
implementation("com.google.code.gson:gson:2.9.1")
This lets us handle the JSON we’ll get back from the API. Now, if we run the app we’ll see some information about Chewbacca:
$ ./gradlew run
> Task :app:run
Name: Chewbacca
Height: 228
Hair color: null
Eye color: null
BUILD SUCCESSFUL in 2s
Conclusion
The beauty of Kotlin for Java developers is that it fits fairly easily into your existing mental model. Kotlin lets you program inside the JVM, with all its intensive optimization and vast ecosystem, but with a functional language that is in some ways “more Java than Java,” yet easy to grasp and powerful. You can also use Kotlin alongside Java, so you don’t have to choose one or the other.
There’s a lot more to Kotlin, including an extension function (which lets you add class functions without subclasses), coroutines, more functional capabilities, lack of checked exceptions, and a simplified approach to object-oriented programming. We’ll continue exploring Kotlin and its features in my next article.