There is a base class:
class Base {
func foo<S: Base>(to value: S) {
print("Base class foo")
}
}
and a derived ones from Base:
class One: Base {
func foo(to value: Two) {
print("foo: Two")
}
}
class Two: Base {
func foo(to value: One) {
print("foo: One")
}
}
class Three: Base {
func foo(to value: One) {
print("foo: One")
}
}
Example usage:
var sample: Base = One()
sample.foo(Two()) // expected "foo: Two"
sample.foo(Three()) // expected Base class implementation to be called "Base class foo"
The idea is to get called the “specialized” func variant from One
, Two
or Three
in case the derived class’s implementation exists or default to Base
class implementation using generics. My attempt was to add the keyword override
but the compiler reports the derived class’s function does not override anything and only the base class func is called every single time…