When should I (and should I not) use Scala’s @inline annotation?

Never @inline anything whose implementation might reasonably change and which is going to be a public part of a library.

When I say “implementation change” I mean that the logic actually might change. For example:

object TradeComparator extends java.lang.Comparator[Trade] {
  @inline def compare(t1 : Trade, t2 : Trade) Int = t1.time compare t2.time
}

Let’s say the “natural comparison” then changed to be based on an atomic counter. You may find that an application ends up with 2 components, each built and inlined against different versions of the comparison code.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)