Considering a move to Kotlin? Coming from a Java background?
In this short series of blog posts, I’ll take a look at familiar, straightforward Java concepts and demonstrate how you can approach them in Kotlin.
While many of these points have already been discussed in earlier posts by colleagues, my focus is simple: how you used to do it in Java, and how you do it in Kotlin.
Case 2:
You need a simple object.
Just data.
No behavior.
No clever tricks.
And yet, Java somehow turns this into a small project.
Continue reading →
Considering a move to Kotlin? Coming from a Java background?
In this short series of blog posts, I’ll take a look at familiar, straightforward Java concepts and demonstrate how you can approach them in Kotlin.
While many of these points have already been discussed in earlier posts by colleagues, my focus is simple: how you used to do it in Java, and how you do it in Kotlin.
Case 1:
You are working on an application in Java and you need a reusable way to modify a String.
Nothing fancy.
No frameworks.
Just a small helper.
Continue reading →
Interoperability between Java and Kotlin is great, but the difference in how nullability is treated can sometimes pose interesting problems.
This article tackles one particular problem and introduces some Kotlin concepts in the process.
Continue reading →
A Java text block is an easy way to have a multiline string value. But there is a catch if we want to use a text block with the assertion method isEqualTo. Suppose you have written a piece of code that create a new string value where the line endings are defined using System.lineSeparator(). The string value would have the line ending \n on Linux and MacOS systems, and the line ending \r\n on Windows system. But a Java text block will always use the line ending \n on every platform, including the Windows platform. If you would run your tests on a Windows platform then the assertion using isEqualTo will fail, but the test will pass on Linux or MacOS systems. This is a problem if you are working with developers using different operating systems. Therefore it is better to use the method isEqualToNormalizingNewlines for these type of assertions. AssertJ will make sure the line endings are the same and the tests will pass independent of the operating system the tests are run on.
Continue reading →
In order to calculate an average for a list of numbers, file sizes, durations, or range of numbers, or a table with columns containing numeric values you can use the math avg command. This command is part of the math module of Nushell. When the input is a list then the result is a single value with the average of all values in the list. If you use a table as input the result is a record where the key is the column name and the value the average of all values in that column. Finally it is possible to have a single value as input and the result is the same value obviously.
Continue reading →