[英]Problem with getter and setter with variable name same as a function
我使用getter和setter解析JSON文件(使用Gson)。 一切正常。 但是在我的JSON中,我有一個名為“ switch”的變量。 如果我像這樣在班級中加入這個名字
專用字符串開關;
這是行不通的,因為switch是Java的功能,但是如果我想進行解析,則必須使用這個名稱。
想要我能做嗎?
謝謝
抱歉,我對Java非常陌生,我還在學習。
使用GSON的字段命名支持是可能的
@SerializedName("switch")
private String Switch;
public String getSwitch ()
{
return Switch;
}
public void setSwitch (String aSwitch)
{
Switch= aSwitch;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.