Joao Alves

Engineering Manager at IndeedFlex

Recent posts

Feb 16, 2018
Kotlin Sealed Classes — enums with swag

image

Hi there everyone, welcome to article number 6 on the series. Today we’ll be looking at Kotlin Sealed classes and how they can take enums to a completely different level and add them some swag. Let’s start with a basic enum in Java and see how it looks in Kotlin:

public enum BasicScreenStateJava {
    ERROR,
    LOADING,
    DATA
}
enum class BasicScreenState {
    ERROR,
    LOADING,
    DATA
}

Pretty simple and pretty similar right? Enums are already pretty concise in Java so Kotlin doesn’t save us any boilerplate with these. Regarding functionality, they’re also very simple as there’s not much we can do with them.

Jan 30, 2018
Parcelable in Kotlin? Here comes Parcelize

image

Hey everyone, welcome to article number 5 in the series where we’re going to look into how to handle Parcelables in Kotlin. In the previous article we looked into data classes and today we’re going to see how we can have our data classes implementing the Parcelable interface.

The most basic use case for using Parcelable is when we need to pass a model from one activity to another. When passing primitive types is pretty straight forward but when we want to pass our own objects we need to do something to them:

Jan 15, 2018
Kotlin data classes — enough boilerplate

image

Hi everyone, we already looked into some differences between Kotlin and Java syntaxes in the previous 2 articles of the series. Today we’ll look into Kotlin data classes and how concise they are compared to POJOs (Plain Old Java Objects) and how much boilerplate we can get rid of by moving to Kotlin data classes.

First, let’s take a look at a simple POJO representing a Person with 4 properties (name, age, email and phone):

Jan 3, 2018
Kotlin Syntax Part II — when did this switch happen?

image

Hey everyone, hope you had an amazing Christmas and an awesome new year’s eve. Welcome to article number 3 of the series and the first one of 2018. In the previous article we went through some of the Kotlin Base Syntax, today is part II of the syntax mini-series, and we’ll look into a few more examples of Kotlin syntax in action.

To recap, in the previous article we talked about Classes, Functions, Variables, Nullability and about the poor semi-colon operator almost not being needed anymore.

Dec 20, 2017
Kotlin Syntax Part I — why am I excluded?

image

Hi everyone again, welcome to article number on 2 of the Kotlin Playground Series. There wasn’t that much code in the previous article but if you read it, you probably saw some new syntax that you’re not familiar with if coming from Java.

In this and following article I’ll cover some of Kotlin base syntax as I believe it’s important before we jump into other examples. But enough talk and let’s look at some Kotlin code.