This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // g100pon #56 数値型(Javaとの相違点など) | |
| // 実数は指定が無い限りBigDecimal | |
| assert (0.5).class == java.math.BigDecimal | |
| // Float同士の加減乗算の結果はDouble(JavaではFloat) | |
| assert (1f + 2f).class == java.lang.Double | |
| assert (1f - 2f).class == java.lang.Double | |
| assert (1f * 2f).class == java.lang.Double | |
| // Float同士の除算の結果はDouble | |
| assert (1f / 2f).class == java.lang.Double | |
| // 整数同士の除算の結果は実数(Javaでは整数) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // g100pon #85 ブラウザで任意のURLを表示(OS非依存) | |
| // Java6以降で動作 | |
| import java.awt.Desktop | |
| Desktop.getDesktop().browse args[0].toURI() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // g100pon #99 JavaとしてもGroovyとしても正当だが結果が異なるコード | |
| // GroovyでもJavaでも動きます | |
| public class Code099 { | |
| public static void main(String[] args) { | |
| //Java:0.6666666666666666,Groovy:0.6666666667 | |
| System.out.println(2.0/3); | |
| //おまけ:Java:0,Groovy:0.5 | |
| System.out.println(1/2); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Grab('jline:jline:0.9.94') | |
| def c = new jline.ConsoleReader() | |
| while (l = c.readLine('$ ')) println "${_ = evaluate(l)}" | |
| println '' |
NewerOlder