groovy
fightingwy
这个作者很懒,什么都没留下…
展开
-
groovy 泛型
groovy 泛型就是鸭子类型。T类似go语言中的interface,可以是任意类型public class DictType{private T localt;}class Example { static void main(String[] args) { // Creating a generic List collection ListType<String> lststr = new ListType<>();原创 2021-06-10 13:49:36 · 440 阅读 · 0 评论 -
groovy面向对象继承多态 抽象类
groovy对象的继承通过关键字extends 基类名字,只能继承共有变量或者函数,private不能直接继承class Example{ static void main(String [] args){ Student st = new Student(); st.StudentID = 88; st.Marks1 = 100; st.name="wuyong"; println(st.name); }原创 2021-05-21 16:15:54 · 1029 阅读 · 0 评论 -
Groovy异常捕获
try{…}catch{}finally{}finally无论如何都会走class Example { static void main(String[] args) { try{ File file = new File("E://file.txt"); FileReader fr = new FileReader(file); }catch(Exception e2){ println("have so原创 2021-05-14 17:40:01 · 1294 阅读 · 0 评论 -
groovy 时间Date
Date是一个时间类,可以用它实例化出对象。class Yong { static void main(String [] args){ Date date = new Date("05/11/2021"); Date date1 = new Date("06/10/2021"); println(date.after(date1)) println(date.toString()); }}falseTue May 11 00:00:00 CST 2021after()测原创 2021-05-13 17:31:12 · 1514 阅读 · 0 评论 -
groovy map 映射
containsKey(String keyname) 判断是否包含某个keyget 通过key获取value. dic.get(“name”)dic.keySet()打印所有滴key值。put(Object key, Object value)class Test{ static void main(String[] args){ def dic = ["name":"wuyong","password":"123456"]; println(dic.containsKey("name"原创 2021-05-13 16:08:11 · 146 阅读 · 0 评论 -
Groovy列表
末尾追加size()数组长度class Example { static void main(String[] args) { def list1 = [] ; def list2 = [1,2,3,4]; list2.add(12); list2.add(12); println(list2.size()); println(list2); } }6[1, 2, 3, 4, 12, 12]contains 包含元素返回为原创 2021-05-13 15:37:17 · 1112 阅读 · 0 评论 -
groovy字符串操作
1.字符串的拼接类似python 就是使用 “+”class Test{static void main(String [] args){ String a = "hello"; String b = " world \n"; def c = a+b; println(c);}}字符串索引class Test{static void main(String [] args){ String a = "hello"; String b = " world"; def c =原创 2021-05-12 19:22:43 · 859 阅读 · 0 评论 -
groovy 数字转换比较min max
数字转换import java.io.Fileclass Example { static void main(String[] args) { def x = 211; println(x.intValue()); println(x.intValue()); def y=31.1; println(y.intValue()); println(y.byteValue()); }}数字比较转换y.comp原创 2021-05-12 11:16:45 · 785 阅读 · 0 评论 -
groovy读写文件删除文件,文件复制,目录创建
文件写入首先导入java.io.File package, new File object,append在文件末尾追加。import java.io.Fileclass Text{ static void main(String[] args){ def file = new File("test.txt"); file.append("hello guys"); }}文件写入覆盖式import java.io.Fileclass Text{ static void main原创 2021-05-11 18:01:15 · 1266 阅读 · 0 评论 -
groovy 函数方法
定义一个Test 类,然后定义一个静态的数字通过static的静态方法通过this来调用staic 数字并打印class Test{ static int y =200;//只有是静态的变量下面方法才能调用 static def Display(int j){ println("display"); println(j); } public static int test(){ Display(this.原创 2021-05-11 15:24:49 · 759 阅读 · 0 评论 -
groovy初识hello world
进入该链接www.groovy-lang.org/download.html获得Windows安装程序部分。Download.在cmd中执行groovysh类似go的fmt.Println().原创 2021-05-10 17:27:20 · 95 阅读 · 0 评论