Home » JVM Languages » Kotlin

Kotlin

Comparing Kotlin performance with Graal and C2

You may have heard of Graal, the new JIT compiler for the JVM written in Java. It is available inside the JDK since Java10 and in the future will probably become the standard of the JDK. If you are interested, you can find more information here: https://www.infoq.com/articles/Graal-Java-JIT-Compiler In the last year I mostly worked with Kotlin and as personal project I ...

Read More »

Testing Kotlin with Spock Part 3 – Interface default method

Kotlin allows you to put method implementation in an interface. The same mechanism can be found in Java interfaces as default methods (and also Groovy or Scala traits). Let’s see the difference between the Kotlin and Java default methods in interface by testing it with Groovy and Spock. What do we want to test? We often have an interface for ...

Read More »

Kotlin DSL: from Theory to Practice

I’ll try to explain the language syntax as simple as possible, however, the article still appeals to developers who consider Kotlin as a language for custom DSL building. At the end of the article I’ll mention Kotlin drawbacks worth taking into account. The presented code snippets are relevant for Kotlin version 1.2.0 and are available on GitHub. What is DSL? ...

Read More »

Kotlin and JUnit 5 @BeforeAll

Introduction In Kotlin, classes do not have static methods. A Java equivalent semantic can be provided to callers using the concept of a companion object though. This post will go into details of what it takes to support a JUnit 5 @BeforeAll and @AfterAll annotation which depend on the precense of a static methods in test classes. BeforeAll and AfterAll in Java Junit ...

Read More »

Testing Kotlin with Spock Part 1 – Object

The object keyword in Kotlin creates singleton in a very convenient way. It can be used for example as a state of an operation. Spock Framework is one of the most expressive and readable test framework available in the Java ecosystem. Let’s see how Kotlin object can be used in the Spock tests. What do we want to test? We ...

Read More »

Defending Public-By-Default in Kotlin

Some people have spoken against Kotlin’s decision to make classes, methods, etc. public by default (when no visibility modifier is used), and I would just like to pitch in on why I think JetBrains made the right decision on this one. Those who are against it bring up the principle of hiding everything that you can get away with in ...

Read More »

Kotlin – Reified type parameters sample

This post walks through a sample that demonstrates Kotlin’s ability to cleverly reify generic type parameters. So consider first a world where Kotlin does not support this feature, if we were using the Jackson library to convert a JSON to a Map with String based keys and Integer based values, I would use a code along these lines: @Test fun `sample ...

Read More »