scala在编译&优化的时候,有时候会返回个inline warning.但是,实际上我们写代码已经不能再优化了. 比如如下这个例子:
yu:~ yu$ scala -version Scala code runner version 2.11.7 -- Copyright 2002-2013, LAMP/EPFL yu:~ yu$ scala -optimize -Yinline-warnings Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05). Type in expressions to have them evaluated. Type :help for more information. scala> object O { Map( | "a" -> 0, "b" -> 1, "c" -> 2, "d" -> 3, "e" -> 4, | "a" -> 0, "b" -> 1, "c" -> 2, "d" -> 3, "e" -> 4, | "a" -> 0, "b" -> 1, "c" -> 2, "d" -> 3, "e" -> 4, | "f" -> 5, "g" -> 6, "h" -> 7, "i" -> 8) } warning: At the end of the day, could not inline @inline-marked method ->$extension warning: At the end of the day, could not inline @inline-marked method ->$extension warning: At the end of the day, could not inline @inline-marked method ->$extension warning: At the end of the day, could not inline @inline-marked method ->$extension defined object O
我们可以看到有个issue ,讲的就是这件事.它是12年底建立的,但一直没啥好的回答...可怜我为了关掉这个warning连带好几个其它warning都不能用了.
不过,今年五月终于有结果了.
issue最后提到的solution如下:
Adriaan Moors added a comment - 08/May/15 11:18 PM We're very actively working on a new optimizer (based on Miguel's work). By "we" I mean Lukas (the assignee). Check it out in 2.11.6 with `-Ybackend:GenBCode` – will be default in 2.12.
因此,我2.11.7版本的,可以写成这样:
yu:~ yu$ scala -optimize -Yinline-warnings -Ybackend:GenBCode Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05). Type in expressions to have them evaluated. Type :help for more information. scala> object O { Map( | "a" -> 0, "b" -> 1, "c" -> 2, "d" -> 3, "e" -> 4, | "a" -> 0, "b" -> 1, "c" -> 2, "d" -> 3, "e" -> 4, | "a" -> 0, "b" -> 1, "c" -> 2, "d" -> 3, "e" -> 4, | "f" -> 5, "g" -> 6, "h" -> 7, "i" -> 8) } defined object O scala>
这就没问题了.
顺便一说,目前为止2.12才到m2,各种相关的包都还没有.先只能2.11.7用着了只能.