以下是编写Groovy程序时应用的条件:
- 在groovy中,没有必要像Java中那样在语句的末尾添加分号。
例:
package com.app
class Demo {
static void main(args) {
print ("Welcome to srcmini tutorial on Groovy... ")
}
}
输出:
- 在groovy中,我们可以不使用圆括号就打印一行
例:
package com.app
class Demo {
static void main(args) {
print "Welcome to srcmini tutorial on Groovy... "
}
}
输出:
- 在groovy中,可以在字符串中使用双引号和单引号。
例:
package com.app
class Demo {
static void main(args) {
print 'Welcome to srcmini tutorial on Groovy...'
}
}
输出:
- 就像在Java中一样,我们可以有单行注释,也可以有多行注释。
例:
package com.app
class Demo {
// this is a single line comment
/*
*
* this is a
* multi-line comment
*/
static void main(args) {
print "Welcome to srcmini tutorial on Groovy... "
}
}
输出:
- 在Groovy中,不需要类或main函数。
例:
package com.app
print "Welcome to srcmini tutorial on Groovy... "
输出:
评论前必须登录!
注册