Nicole
06/19/2019, 12:43 AMdata class Component(val active: Boolean) {
val getList get() = listOf("empty")
val isPoorlyNamed get() = 10
val isCorrectlyNamed get() = true
}
JVM code:
Component component = new Component(false);
component.getActive();
component.getGetList();
component.isPoorlyNamed();
component.isCorrectlyNamed();
Proposal: To better match Java Bean naming conventions:
val active -> boolean isActive() - Boolean return maps to “isProperty”
val getList -> List<String> getList() - Already prefixed with “get” -> leave it
val isPoorlyNamed -> int getIsPoorlyNamed() - Prefixed with “is”, but isn’t a boolean -> add “get” prefix
val isCorrectlyNamed -> boolean isCorrectlyNamed() - Same as todaygildor
06/19/2019, 1:27 AMgildor
06/19/2019, 1:27 AMkarelpeeters
06/19/2019, 7:59 AMisPoorlyNamed in the first place?cbruegg
06/19/2019, 9:30 AMgetList)raulraja
06/20/2019, 11:24 AMactive: Boolean is a good example. If Kotlin is generating today getActive in the getter property as seen from java that does not follow the javabeans conventions (I have not verified that). I think it’s a legit concern and most likely an expectation of many frameworks that use reflection.benleggiero
06/26/2019, 3:16 AMgildor
06/26/2019, 3:24 AMIf Kotlin is generating todayFor propertyin the getter property as seen from java that does not follow the javabeans conventionsgetActive
isActive Kotlin generates method isActive() and setActive and field isActive, which perfectly follows Java bean convention
If you have property active it will generate getActive and setActive with field active, which also follows Java bean convention, because is is not requirement, but optional naming convention for booleans, get prefix is still completely validgildor
06/26/2019, 3:26 AMgildor
06/26/2019, 3:28 AMis prefix in Kotlin, but with get prefix in Java, just use JvmName:
@get:JvmName("isActive")
var active = falsegildor
06/26/2019, 3:29 AMIt addresses what I would consider a bug in the compilerWhat kind bug? what is exactly not consistent? Also remember that this is backward incompatible change, it will break all Kotlin/Java interop of existing code
benleggiero
06/26/2019, 4:08 AMget or is as a prefix, even if there is a logic behind which it chooses.
I think if we put in zero special cases (all getters with auto-generated JVM names start with get), that's OK.
I think that if we put in one special case for Boolean getters (their auto-generated JVM names all start with is), that's OK.
I think that if there's some logic where the special case is only sometimes applied (Boolean getters with auto-generated JVM names start with is if and only if their Kotlin counterpart also starts with is, otherwise they start with get), that's not OK and is unnecessarily confusing/inconsistent.gildor
06/26/2019, 5:07 AMIt’s not obvious whether a given Boolean will generateIt’s obvious.orgetas a prefixis
is generated if your property has is prefix`
all getters with auto-generated JVM names start withThis will make Java interop not so pleasant, you will have getSomething instead isSomething everywhere, even if original property has)get
is prefix
Also, existing behaviour have a lot of sense not only for Java interop, but also for any kind of serialisation, when to map Kotlin property to some serialized property you can choose between boolean property with is prefix or without it.
Again, all this “would be good to have” probably doesn’t make a lot of sense because it will break a lot of code without any significant advantage