java 反射 fields数量变多

1.这是反射过程

   @Override
    protected String createTable(String tableName,Class bean) {


        Field[]  fields= bean.getDeclaredFields();
        StringBuilder stringBuilder =new StringBuilder();
        stringBuilder.append("create table if not exists "+tableName+" ( ");
        for (int i = 0; i <fields.length ; i++) {
            TLog.error(fields[i].getName());
            if (i==fields.length-1){
                stringBuilder.append(" "+fields[i].getName()+" varchar(40)");
            }else {
                stringBuilder.append(" "+fields[i].getName()+" varchar(40),");

            }
        }

        stringBuilder.append(" );");
        return stringBuilder.toString();
    }

2.这是反射的bean对象

public class City {

    public City(String id, String name, String cityCode) {
        this.id = id;
        this.name = name;
        this.cityCode = cityCode;
    }


    public String id;

    public String name;

    public String cityCode;



}

3.这是log日志

01-11 10:16:17.467 5631-5631/com.ccj.archdesigns E/TLog: cityCode
01-11 10:16:17.467 5631-5631/com.ccj.archdesigns E/TLog: id
01-11 10:16:17.467 5631-5631/com.ccj.archdesigns E/TLog: name
01-11 10:16:17.467 5631-5631/com.ccj.archdesigns E/TLog: $change
01-11 10:16:17.467 5631-5631/com.ccj.archdesigns E/TLog: serialVersionUID
阅读 3.5k
3 个回答

是因为AndroidStudio里InstantRun的问题,关闭这个功能就不会出现那个$change了:

File | Settings | Build, Execution, Deployment | Instant Run

好像只有在Android Studio2.1里会出现这个情况,在Android Studio2.2.3 里没有这个情况。google似乎修改了这个bug,https://code.google.com/p/and...

你确定你的pojo没有被序列化?

$change什么鬼不太懂,serialVersionUID实现序列化接口就会有,一般Bean都会实现这个接口,可以对字段统一做个过滤

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏