nbilyk
December 10, 2016, 10:51pm
1
It would be nice if there were an annotation that could mark a method as being protected for overrides, but private for invocation.
Use case:
class Component {
var propertiesValid = false
private fun validateProperties() {
if (propertiesValid) return
propertiesValid = true
updateProperties()
}
// Can override, but not invoke directly.
@privateInvoke protected open fun updateProperties() {
// Do work.
}
}
I think that even if the Kotlin compiler could enforce it, there still won’t be a Java counterpart. So either you can’t subclass in Java, or it will be exposed. I think both ways will be a no go.
nbilyk
December 12, 2016, 12:03am
3
I don’t mind if it’s not enforced at runtime, a compiler warning would be fine.
yole
December 12, 2016, 12:16pm
4
There would not be any compiler warning if you used such a class from Java code, because there’s nothing to warn about from Java’s point of view.