is there any difference in these two approaches? `...
# announcements
s
is there any difference in these two approaches?
Copy code
Utils.Kt
object Utils {
      fun doSomething(){
}

vs

Utils.Kt
fun doSomething(){
}
a
First one is a class with a single instance and an instance method called
doSomething
Second one is a static function called
doSomething
that is surrounded by a final class
s
performance wise, would 2nd approach be better?
k
Performance difference shouldn't be that big.
But as always: measure it.
3
a
first approach means an instance of
Utils
has to be created once, but that would be negligible if you call
doSomething
a lot of times, so without any measurements I'd guess that they are similar in performance
and I wouldn't make the choice of static vs non-static function on the basis of performance