https://kotlinlang.org logo
#android
Title
# android
a

Ananiya

06/05/2020, 5:23 PM
is there difference between them
👍 1
h

Himanshu Sharma

06/05/2020, 5:35 PM
the difference is same
Copy code
//1st
public static int MY_FOO = 9

//2nd
public int MY_FOO = 9
anything inside companion object is singleton and the value is shared among all the class instances, whereas for your 2nd option each instance of the class can have its own value.for MY_FOO.
n

nino

06/05/2020, 7:35 PM
I wouldn't call it singleton but simply static.
1
2 Views