Extension objects/classes


#1

I do not know if this is the right forum to ask (do the kotlin language developers look into this forum?)  this questions, if not could someone point me in the right direction?

I’m curious why the developer decided that the extension mechanismus only is usable for a subset of thenested declarations from a class and not for all of it.

we can write

class X{
  val a:Int
          get() = ???
  var b:Int
          get() = ???
          set(v:Int) {???}

  fun c(???){
          ???
  }

  class D{
          ???
  }

  object E{
          ???
  }
}

But we can only write:

  val X.a:Int
          get() = ???
  var X.b:Int
          get() = ???
          set(v:Int) {???}

  fun X.c(???){
          ???
  }   

And not:

  class X.D{
          ???
  }

  object X.E{
          ???
  }

Is their any obvious reason why the extension mechanism does not work for any Nested declaration of a Class?


#2

The logic behind this is: extensions may be called on instances of classes, not on classes themselves. Since classes and objects are not members of instances, but only of classes, such extensions are not supported.