uehaj's blog

Grな日々 - GroovyとかGrailsとかElmとかRustとかHaskellとかReactとかFregeとかJavaとか -

「int i = null」はエラー

groovy 1.8からは、「int i = null」はエラーです。

$ groovy -e 'int i=null'
Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead
at script_from_command_line.run(script_from_command_line:1)

いままでのGroovyは、intは配列の場合以外は常にIntegerと等価でしたが、プリミティブの最適化を行うこれからはこんな違いがでてきます。
「Integerとは違うのだよ!Integerとは!」
まあレアケースですけど。