[英]Error: What's wrong with this Groovy code?
這個Groovy代碼有什么問題?
class Pretending {
public int count=0
Object get(String name)
{
return 'hi'
}
void set(String name, Object value)
{
count++;
}
def anto = new Pretending();
在這里,我試圖擴展Groovy set / get方法的功能,但是當我嘗試通過groovy Pret
(我的文件名為Pret)執行此腳本時,我在最后一行收到錯誤,指出意外的標記 。 這是什么原因? 我是Groovy領域的新手,所以我無法弄清楚!
您缺少花括號。 嘗試:
class Pretending {
public int count=0
Object get(String name)
{
return 'hi'
}
void set(String name,Object value)
{
count++;
}
def anto = new Pretending();
}
class Pretending {
public int count=55
Object get(String name) {
'hi'
}
void set(String name,Object value) {
count++;
}
}
a = new Pretending()
assert a.any_undef_var == 'hi'
assert a.count == 55
assert a.@count == 55
a.set "v", 4
assert a.count == 56
我認為這是您想要實現的功能+其他功能
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.