A normal val is OK, and is initialized.
class MyClass {
companion object {
private val TAG = MyClass::class.java.simpleName
}
}
But const val causes compilation error.
class MyClass {
companion object {
private const val TAG = MyClass::class.java.simpleName
}
}
error log
MyClass.kt:27:33: error: const 'val' initializer should be a constant value
private const val TAG = MyClass::class.java.simpleName
It seems unintuitive that simpleName cannot be defined as a const val.