Using this in class parameter list


#1

Currently this is not defined in class parameter lists. I’d like to use this like this:

abstract class Tag(repr: String = this.javaClass.simpleName)

I can workaround this limitation:

abstract class Tag(repr: String? = null) {
  val repr: String = repr ?: this.javaClass.simpleName
}

However I’d prefer the first way. Would it be possible to allow it in future Kotlin versions?


#2

The default value for the parameter is added to the stack before the superclass constructor is called. At that stage you cannot call any methods on the instance that is being constructed. This is the same limitation as for Java superclass constructor invocations.