import kotlin.collections.* @CompileTimeCalculation open class MyArrayList: ArrayList() { var addCounter = 0 override fun add(element: E): Boolean { addCounter++ return super.add(element) } } @CompileTimeCalculation class MyOtherArrayList: MyArrayList() { override fun addAll(elements: Collection): Boolean { return true // do nothing } } @CompileTimeCalculation fun test(list: MyArrayList): String { list.add(1) list.add(2) list.add(3) val otherList = arrayListOf(4, 5, 6) list.addAll(otherList) list.addAll(emptyList()) return "Counter " + list.addCounter + "; size " + list.size } const val testResult1 = test(MyArrayList()) const val testResult2 = test(MyOtherArrayList())