Tarun
04/10/2018, 9:29 AMcompanion object
, than those variable are treated as static in Java
But when I try to access those variable in a java project, which is using library, It is like :
MyClass.Companion.abcVariable
I searched and found I had to append @JvmStatic in front of variable so that java can access it directly like :
MyClass.abcVariable
This works for classes
but for interfaces
it requires a min API level of 24 and my Min API level is 21
Is there any other way to directly access companion object variables for interface
in API projects supporting min API level less than 24 like :
MyClass.abcVariable
gildor
04/10/2018, 9:35 AMconst
(if it’s possible for your case), otherwise your property will be compiled to interface default method (java 8 required) and it doesn’t work on old AndroidTarun
04/10/2018, 9:46 AMconst
is working for constants
-@JvmField is not working for properties and is giving compile time error as JvmField
can not be applied to a property inside companion object
For functions in companion object
None of these two are working
I need something for properties as well as functionsgildor
04/10/2018, 9:51 AMis not working for propertiesWhat do you mean? yes, of course JvmField converts property to field, but it works: Kotlin will generate raw JVM field instead of property (field + getter) and this is your only solution
gildor
04/10/2018, 9:53 AMTarun
04/10/2018, 9:57 AMcompanion object
member variables and functionsgildor
04/10/2018, 9:59 AMTarun
04/10/2018, 10:02 AMgildor
04/10/2018, 10:03 AMTarun
04/10/2018, 10:10 AM