首先看文档:
The integral literal types are the same as in Java:
byte
char
short
int
long
java.lang.BigInteger
-
这和Java一样。 兼容Java的
-
比如定义一些整数变量
-
class StrStudy { static void main(String[] args) { byte b = 1 char c = 2 short s = 3 int i = 4 long l = 5 } }当然也可以使用def关键字定义一个整数类型变量 - Java中有二进制 八进制 16进制 那么在groovy也有
- Binary literal 二进制
- Binary numbers start with a
0bprefix: - 二进制使用ob表示
-
class StrStudy { static void main(String[] args) { int xInt = 0b10101111 println(xInt) } }Octal literal(八进制)
-
Octal numbers are specified in the typical format of
0followed by octal digits -
八进制以 0 开头
-
class StrStudy { static void main(String[] args) { int xInt = 077 println(xInt) } }Hexadecimal literal(十六进制)
-
Hexadecimal numbers are specified in the typical format of
0xfollowed by hex digits -
16进制以0x开头
-
class StrStudy { static void main(String[] args) { int xInt = 0x77 println(xInt) } }
Groovy的整数类型与Java兼容,包括二进制、八进制和十六进制。二进制前缀为ob,八进制以0开头,十六进制则以0x开头。
59

被折叠的 条评论
为什么被折叠?



