https://kotlinlang.org logo
Title
s

Sam Garfinkel

01/29/2020, 4:31 PM
Is there a workaround for the
Calling non-final function 'function' in constructor
warning when configuring subclasses of Gradle tasks? For example:
open class ChildJavaExec: JavaExec() {
    init {
         workingDir("foo/bar")
    }
}
Not sure if I should just ignore it? Tasks need to be non-final in order for Gradle to inject and construct them.
c

Czar

01/29/2020, 5:19 PM
There is this tidbit in docs: https://kotlinlang.org/docs/reference/classes.html#derived-class-initialization-order Which explains why it's dangerous to do it. If you're fine with it, you can ignore. The risk is always there but it doesn't always matter.
s

Sam Garfinkel

01/29/2020, 6:45 PM
Agreed, I was already aware of why this is a bad pattern and is being linted. I suppose the workaround in this particular case is to explicitly call that method in the parent with
super