Search code examples
scalascala-compiler

Is it possible to override an inline function?


I am assuming that Scala compiler will inline the function after it has been overriden.


Solution

  • The optimizer for the JVM will simply refuse to inline any method that is not effectively final (either final itself, or in a sealed class or object, or stuff like that). So obviously it won't online an overridden method.

    On JavaScript, the optimizer can inline overridden methods when it can prove some way or another that it has the right to do so. In some cases, yes, it will inline a method from a subclass.