类 – 在Groovy中分配对象属性的简便方法?
发布时间:2020-12-14 16:33:59 所属栏目:大数据 来源:网络整理
导读:我使用这个约定创建Groovy对象 Item item1 = new Item( name: "foo",weight: "150") …有一个操纵属性对象的速记惯例?这样的东西 item1( name: "hello",weight: "175") //this does not work,btw ;-) …代替… item1.name = "hello"item1.weight = "175" 解
我使用这个约定创建Groovy对象
Item item1 = new Item( name: "foo",weight: "150") …有一个操纵属性对象的速记惯例?这样的东西 item1( name: "hello",weight: "175") //this does not work,btw ;-) …代替… item1.name = "hello" item1.weight = "175" 解决方法
你有方法,as described by the great Mr Haki
item1.with{ name = "hello" weight = "175" } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |