首先看文档:
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
0b
prefix: - 二进制使用ob表示
-
class StrStudy { static void main(String[] args) { int xInt = 0b10101111 println(xInt) } }
Octal literal(八进制)
-
Octal numbers are specified in the typical format of
0
followed by octal digits -
八进制以 0 开头
</