When code evolves we usually deprecate old code. Sometimes we come across deprecations without any hints with what to replace it with. Kotlin has a solution for this by allowing you to specify a replace instruction.
Kotlin data classes and annotations go really well together, but it is easy to mess it up.
When dealing with Maps in Kotlin, sometimes we’re only interested in entries for which the value is not
Although the Kotlin Standard Library contains a
filterValues function that seems to be appropriate, this function
does not do any type conversions, resulting in a
Map which won’t contain
but is still a Map with values of a nullable type according to the compiler. There is a feature request
for the JetBrains team to add this functionality, but for now it has not been implemented (yet?).
If you write lots of Kotlin code you might have noticed that it is annoying to write the named parameters when calling functions or when creating a new instance of class.
The Kotlin standard library contains a lot of helper functions on top of the Java standard library for our convenience.
Some of those functions help us in converting between different data types.
For example, the
String.toInt() function converts a number formatted as
String to its
But how do we accomplish the same with a
Char? Spoiler alert: NOT by using
Functions defined in Kotlin companion objects are often seen as the 'equivalent' of static methods in Java. Although there are some similarities, there are also some caveats you should be aware of. For example, how to use method references (or, to be pedantic: function references) to refer to functions defined in a companion object.
It’s quite common in a microservice style architecture to provide a type-safe client library that other services can use to communicate with your service. This can be package with a Retrofit client published to nexus by the maintainer of the service. Some projects might also generate that code from a OpenAPI spec or a gRPC proto file.
Micronaut makes it possible to easily configure your application using the provided mechanisms based on Spring and Grails. This blog demonstrates how to configure a Kotlin based Micronaut application using Micronaut version 1.0.0.RC1.