2013-03-07 28 views

回答

4

一個Groovy場是沒有getter和setter的公共屬性:

@groovy.transform.TupleConstructor(includeFields=false) 
class Invoice { 
    Integer serie, number // properties 
    BigDecimal total // property 
    public Integer type // this is a field 
} 


try { 
    i = new Invoice(1, 2, 10.0, 10) 
    assert false 
} catch (e) { 
    assert true 
} 
+1

感謝澄清。有這方面的文件嗎? – 2013-03-07 20:18:42

+1

http://groovy.codehaus.org/Groovy%2BBeans:「如果使用訪問修飾符(public,private或protected)聲明[屬性]的名稱,則會生成一個字段」。 – Will 2013-03-07 22:07:27

+0

感謝您的鏈接 – 2013-03-07 22:39:14