Third episode

For the survivor generation of the JVM there’s a third round of excersizes.

It works in Java too!

One of the key selling points (of this free programming language) is that it is fairly easy to use Java in Kotlin and vice versa. However, Kotlin is of very different essence and therefore some of the language properties that required in Java are missing. Kotlin therefore adds support to expose these nuances for Java modules.

SomeUtilityClass is a Kotlin class we would like to use in Java program. Kotlin doesn’t support static methods, but for example some of the frameworks require them (JUnit @BeforeClass methods, anyone?).

Definition of done: Explore JavaInteroopTest and follow the instructions.

Reference: https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html

Extension functions revisited

Extension functions shouldn’t be abused. That’s why we are going to implement a universal method on Any class that’s going to check if object is null (in terms of it has null reference) or it’s an empty array (for now) - only in this workshop, don’t try this at home.

Pro tip: You can use this reference and switch base on the class type.

Definition of done: Extensions.kt file must compile.

Generics: 'nough said.

Everyone loves Java’s generics. It’s implemented in a fine way with backwards compatibility in mind. Kotlin shares the concepts with Java and throws in some additional general best practices. You can write generics in a similar fashion as in Java, but additionaly you explicitly define covariant/contravariant types.

Read the generics section, then read it again and then try to utilize your findings to make Generics.kt file compile.

Definition of done: Make Generics.kt file compile.

Microservices

Now let’s do something more real. Kotlin works well with Spring Boot so we will try to create a simple HelloWorld resource. Have a look at HelloWorldController in HelloWorldApp and expose helloMessage() as REST service (based on the comments). You can use annotations and everything, you can run the application by running main method in HelloWorldApp.

Definition of done: Make HelloWorldAppIntegrationTest pass.

Topics:

Third episode

For the survivor generation of the JVM there’s a third round of excersizes.

It works in Java too!

One of the key selling points (of this free programming language) is that it is fairly easy to use Java in Kotlin and vice versa. However, Kotlin is of very different essence and therefore some of the language properties that required in Java are missing. Kotlin therefore adds support to expose these nuances for Java modules.

SomeUtilityClass is a Kotlin class we would like to use in Java program. Kotlin doesn’t support static methods, but for example some of the frameworks require them (JUnit @BeforeClass methods, anyone?).

Definition of done: Explore JavaInteroopTest and follow the instructions.

Reference: https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html

Extension functions revisited

Extension functions shouldn’t be abused. That’s why we are going to implement a universal method on Any class that’s going to check if object is null (in terms of it has null reference) or it’s an empty array (for now) - only in this workshop, don’t try this at home.

Pro tip: You can use this reference and switch base on the class type.

Definition of done: Extensions.kt file must compile.

Generics: 'nough said.

Everyone loves Java’s generics. It’s implemented in a fine way with backwards compatibility in mind. Kotlin shares the concepts with Java and throws in some additional general best practices. You can write generics in a similar fashion as in Java, but additionaly you explicitly define covariant/contravariant types.

Read the generics section, then read it again and then try to utilize your findings to make Generics.kt file compile.

Definition of done: Make Generics.kt file compile.

Microservices

Now let’s do something more real. Kotlin works well with Spring Boot so we will try to create a simple HelloWorld resource. Have a look at HelloWorldController in HelloWorldApp and expose helloMessage() as REST service (based on the comments). You can use annotations and everything, you can run the application by running main method in HelloWorldApp.

Definition of done: Make HelloWorldAppIntegrationTest pass.