This article is part of a series of articles where I analyse how some items, of the famous book Effective Java written by Joshua Bloch, are applied in Kotlin.

Contract

Before going into details of the toString implementation lets quickly review its contract: “a concise but informative representation that is easy for a person to read”.

Recipe

Joshua Bloch gives us four advice for writing an excellent toString method that follows its contract.

  1. Should return all of the interesting information contained in the object.
  2. Self-explanatory.
  3. It’s recommended to specify the format of the return value for value classes.
  4. Provide programmatic…

This article is part of a series of articles where I analyse how some items, of the famous book Effective Java written by Joshua Bloch, are applied in Kotlin.

Pair equals / hashCode

As the title of this item states, in Java we should override hashCode whenever we override equals. It is for that reason the Kotlin compiler automatically generates the pair equals and hashCode only for data classes.

Hash code contract

Before going into details of the hash code implementation lets review quickly its contract:

  • internal consistency: the value of hashCode may only change if a property that is in equals changes
  • equals consistency: objects that…

This article is part of a series of articles where I analyse how some items, of the famous book Effective Java written by Joshua Bloch, are applied in Kotlin.

Values classes

In this item Joshua Bloch goes into great detail of how to write an excellent equals method that follows its general contract (reflexivity, symmetry, transitivity, consistency and non-nullity).

The first advice says not to override the equals method for classes where each instance of the class is equal only to itself. On the contrary, it’s appropriate to override equals only on values classes. The equivalent of values classes in Kotlin is…


In this article let’s examine a few situations you might face while you are developing your app using ROOM database. Sometimes there is a need to change our database schema by adding fields or entities.

First of all, let’s assume that we have created an AppDatabase with a data access object class UserDao and a User entity.

@Database(entities = arrayOf(User::class), version = 0)
abstract class AppDatabase : RoomDatabase() {
abstract fun userDao(): UserDao
}
@Entity
data class User(@PrimaryKey val id: Int)

Database version unchanged

Let’s say that we want to add a field name to the User entity.

@Entity data…

Have you ever accidentally pushed a typo that broke your Android build or unit tests? Continuous Integration (CI) is a way to avoid these issues referred as “integration hell”, allowing you to confirm that your changes don’t break your build or any of your tests, giving you a certain degree of confidence that your changes don’t affect the good behavior of your app.

GitLab provides a built-in solution called GitLab CI/CD. This article will walk you through on how to set up basic CI for your Android projects.

We want to be able to configure GitLab CI in a way…


Why do we need small APKs?

Users often avoid downloading apps that seem too large.

One way to make smaller APKs is instead of building a very large single APK which supports all the different possible device configurations, is to create multiple APKs that contain files for specific screen densities, CPU architectures(ABI), languages, … Google Play supports multiple APK feature, it allows you to publish different APKs for your application that are each targeted to different device configurations. Each APK is a complete and independent version of your application, but they all share the same application listing on Google Play…

Marc CALANDRO

Software Engineer at Samsung Electronics

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store