#TeachingKotlin Part 3 - Caveats coming from Java

When you start migrating your Java code to Kotlin, you will encounter multiple subtle changes that might catch you off guard. I’ll document some of these gotchas that I and other people I follow have found and written about. Splitting strings Java’s java.lang.String#split method takes a String as it’s first argument and creates a Regex out of it before attempting to split. Kotlin, however, has two variants of this method. One takes a String and uses it as a plaintext delimiter, and the other takes a Regex behaving like the Java method we mentioned earlier....

December 16, 2019 · 2 min

#TeachingKotlin Part 2 - Variables

Even the variables in Kotlin are supercharged! Let’s start with a simple data class and see how the variables in there behave. data class Student(val name: String, val age: Int, val subjects: ArrayList<String>) To use the variables in this class, Kotlin let’s you directly use the dot notation for accessing. >>> val s1 = Student("Keith Hernandez", 21, arrayListOf("Mathematics", "Social Studies")) >>> println(s1.name) Keith Hernandez >>> println(s1) // data classes automatically generate `toString` and `hashCode` Student(name=Keith Hernandez, age=21, subjects=[Mathematics, Social Studies]) For Java callers, Kotlin also generates getters and setter methods....

September 30, 2019 · 3 min

#TeachingKotlin Part 1 - Classes and Objects and everything in between

Classes in Kotlin closely mimic their Java counterparts in implementation, with some crucial changes that I will attempt to outline here. Let’s declare two identical classes in Kotlin and Java as a starting point. We’ll be making changes to them alongside to show how different patterns are implemented in the two languages. Java: class Person { private final String name; public Person(String name) { this.name = name; } } Kotlin:...

September 23, 2019 · 5 min

#TeachingKotlin - Kotlin for Android Java developers

Anybody familiar with my work knows that I am a fan of the Kotlin programming language, especially it’s interoperability with Java with respect to Android. I’ll admit, I’ve not been a fan since day one. The abundant lambdas worried me and everything being that much shorter to implement was confusing to a person whose first real programming task was in the Java programming language. As I leaped over the initial hurdle of hesitation and really got into Kotlin, I was mindblown....

September 20, 2019 · 2 min