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

后端 未结 2 1025
一向
一向 2020-12-24 11:14

I believe I understand the basics of inline functions: instead of a function call resulting in parameters being placed on the stack and an invoke operation occurring, the de

2条回答
  •  [愿得一人]
    2020-12-24 11:59

    Personally, I use @inline for alias:

    class A(param: Param){
      @inline def a = param.a
      def a2() = a * a
    }
    

    Now, I couldn't find a way to know if it does anything (I tried to jad the generated .class, but couldn't conclude anything).

    My goal is to explicit what I want the compiler to do. But let it decide what's best, or simply do what it's capable of. If it doesn't do it, maybe later compiler version will.

提交回复
热议问题