https://kotlinlang.org logo
#announcements
Title
# announcements
u

uli

02/26/2017, 11:08 AM
Can someone point me to a design document or discussion, why kotlin decided against statics?
a

Andreas Sinz

02/26/2017, 1:23 PM
uli: Because static methods are considered bad design even in java would be my guess. See: http://stackoverflow.com/a/7084473/4706743
u

uli

02/26/2017, 8:21 PM
Hi @Andreas Sinz , Thanks for your reply. I am well aware of the design problems with statics. What i don't see is where companion objects are better. For statics, you have the class object to hold them. For companion objects, an extra object which lives in parallel to the class object is created to hold something, we now don't call static any more. If i go through the list of issues with statics inside you stackocerfliw link, which one is remedied by companion objects? And how? On the other side they bring a relevant performance penality.
a

Andreas Sinz

02/26/2017, 8:30 PM
@uli simple, a
companion object
is an object. it can extend classes, implement interfaces or serve as a value at runtime
2 Views