Hi, how can I set a function abstract for a compan...
# getting-started
a
Hi, how can I set a function abstract for a companion object of a class ?
s
how would that work? are you trying to do something that’d look like this?
Copy code
class Foo {
  companion object {
    abstract fun bar() {}
  }
}
a
Yeah exactly, but without braces for the
bar
function logically
e
companion/singleton objects can't be extended, so what would that even mean?
a
the class also has to be abstract I forgot
d
The companion object is still a singleton and cannot be extended
d
You can make an interface that the companion implements but you’d still need to remember to implement the interface explicitly on the concrete class, no way to have abstract class enforce that concrete’s companion does anything Main benefit of having an interface is so that all of the concretes’ companions have the same function similar to having an abstract fun would do, at the class level