I have a problem that I am not quire sure how to figure out elegantly:

```
abstract class BaseContinuousSingleObjectiveFitnessFunction {

    // Invoke should compute some function, like f(x) = x^2 + 3x + 5
    abstract fun invoke(x: List<Double>): Double

    // This is supposed to take a function that will be called on the result of invoke
    // and return an object derived from this one that has its invoke overriden to call
    // the new function on the result of the original one.
    fun modify(f: (Double) -> Double): BaseContinuousSingleObjectiveFitnessFunction {
        val originalFunction = this
        return object : BaseContinuousSingleObjectiveFitnessFunction() {
            override operator fun invoke(x: List<Double>): Double = f(originalFunction(x))
        }
    }
}

```

Now, this works, but `modify` does not preserve the properties of the derived types.

So for example lets say I add this to the project:

```
class XTimesA(val a: Double): BaseContinuousSingleObjectiveFitnessFunction() {
    override operator fun invoke(x: List<Double>) = x.sumByDouble { a*it }
}

```

Then I want to call modify on it:

```
val f1 = XTimesA(a = 5.0)
println(f1.a) // Works

val f2 = f1.modify { it.pow(2) }
println(f2.a) // This fails because it is not recognized as deriving XTimesA

```

Is there a way to not copy-paste `modify` into every deriving class but still keep access to the properties?