Is there a way to test at compile-time that a constant is a compile-time constant?

后端 未结 3 724
礼貌的吻别
礼貌的吻别 2020-12-19 02:24

Given how difficult it is to know whether an arithmetic final val expression will be compiled to a compile-time constant, and how easy it is to accidentally break compile-ti

3条回答
  •  情话喂你
    2020-12-19 02:48

    You phrased your question as being about determining whether a value is being in-line expanded at points of reference, but it seems though you're actually looking for a way to guarantee it. Is that correct?

    If you make it a def that's annotated for in-line expansion (@inline) you might get what you want.

    @inline def TwentyTwo = 22
    

提交回复
热议问题