开发者

This code looks like, groovy will result in bad performance? Is it so?

I have been reading Groovy for a month or so. Recently i have came across the following code:

class MyBean implements Serializable {
    def untyped
    String typed
    def item1, item2
    def assigned = 'default value'
}

And when I do this :

def bean = new MyBean()
assert 'de开发者_StackOverflow社区fault value' == bean.getAssigned()

However the above code makes GroovyBeans very very impressive, but still my question is this: Even though we haven't created the getter function(getAssigned()), groovy does for us. So is that groovy produce this for all class's even though we are not intended to work in GRoovyBeans? This means that for all class's it creates the setter and getter, even though we wont want? Is this is not the performance issue? Or else my view is worng?


Adding a method to a class won't cause a performance issue, as it doesn't have to be called.

If you want direct access to the property, you can use the Java field operator:

bean.@assigned
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜