Kotlin: Private set for a constructor property

Kotlin doesn’t support private only for set of a constructor property. The following makes both set and get private.

class User(private var name: String)

In some situations, it might be desirable to expose only get as public and keep set as private. Workaround is to use a backing field to support public get and private set.

class User(name: String) {
    var publicName: String = name
        private set
}