I have a question concerning the code below:
open class A() { class object { fun foo() { print("A") } } }
class B() : A() {
class object {
fun foo() {
A.foo() // compiles and prints “AB”
super.foo() // does not compile
print(“B”)
}
}
}fun main(args: Array<String>) {
B.foo()
}
Would be nice if super.foo() in B’s class object would compile. But it doesn’t as in Java. This was always something that annoyed about Java. When I change the hierarchy I have to go into some refactoring work. Astonishingly, noby outside the Smalltalk world ever complained about this. Maybe people see this as natural, because it is the same way in C++. I can understand that “myClass allSubclassesDo: aBlock” as in Smalltalk doesn’t work in Java as not all existing subclasses may be loaded into the code space when iterating over all subclasses and calling static methods. But the other way round in the hierarchy is a different thing.
This is not too important, I know. But it would make things a little more intuitive. Another thing are class instance variables: for every subclass some class variable has a different contents as if every subclass had a new instance of that inherited class variable (hence the name). Also, nobody outside the Smalltalk world things this is a must have, I know. But would be nice …
Regards, Oliver