Android 实体类中命名与关键字冲突(java&kotlin)解决方法

Android 实体类中命名与关键字冲突解决方法 (java&kotlin)

Android 中的解决方法

1. java中的解决方法是在变量名上增加注解,指定序列化时的变量名称

public class DataBean {
        private String appid;
        private String noncestr;
        private String order_code;
        @SerializedName("package")
        private String packageX;
        private String partnerid;
        private String prepayid;
        private String sign;
        private int timestamp;

        public String getAppid() {
            return appid;
        }

        public void setAppid(String appid) {
            this.appid = appid;
        }

        public String getNoncestr() {
            return noncestr;
        }

        public void setNoncestr(String noncestr) {
            this.noncestr = noncestr;
        }

        public String getOrder_code() {
            return order_code;
        }

        public void setOrder_code(String order_code) {
            this.order_code = order_code;
        }

        public String getPackageX() {
            return packageX;
        }

        public void setPackageX(String packageX) {
            this.packageX = packageX;
        }

        public String getPartnerid() {
            return partnerid;
        }

        public void setPartnerid(String partnerid) {
            this.partnerid = partnerid;
        }

        public String getPrepayid() {
            return prepayid;
        }

        public void setPrepayid(String prepayid) {
            this.prepayid = prepayid;
        }

        public String getSign() {
            return sign;
        }

        public void setSign(String sign) {
            this.sign = sign;
        }

        public int getTimestamp() {
            return timestamp;
        }

        public void setTimestamp(int timestamp) {
            this.timestamp = timestamp;
        }
    }

Kotlin中的解决方法

2. 1 只需要在变量名加上`(英文输入法下波浪线的那个键)即可


data class DataBean(
    val appid: String,
    val noncestr: String,
    val order_code: String,
    val `package`: String,
    val partnerid: String,
    val prepayid: String,
    val sign: String,
    val timestamp: Int
)

你可能感兴趣的:(Android,java,Kotlin,android变量名冲突,java解决方法,kotlin解决方法)