Created
October 11, 2010 05:01
-
-
Save toby55kij/619996 to your computer and use it in GitHub Desktop.
This file contains 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 #53 いろいろな型変換(toメソッド、キャスト、as) | |
// toメソッド | |
// 文字から数値へ | |
def a = '123'.toInteger() | |
assert a.class == Integer | |
def b = '123.45'.toBigDecimal() | |
assert b.class == BigDecimal | |
// 数値から文字へ | |
def c = (10*2).toString() | |
assert c.class == String | |
// キャスト | |
def d = (int)(12.5 * 2) | |
assert d.class == Integer | |
// as | |
def e = 123 as String | |
assert e.class == String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment