Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

a weird field appear in android studio

i have a pojo class

run this code

Field[] fields = clazz.getDeclaredFields();

i got a field under Android Studio IDE :

its type is interface com.android.tools.fd.runtime.IncrementalChange its name is $change

My Android Studio version is 2.0 Preview 4

the pojo class which i definded by myself didn't have $change field

when i run the code in eclipse, it works normal.

where did the field come from? how can i avoid this field , is there some setting in Android Studio ?

like image 967
Jackie Cheng Avatar asked Jan 07 '16 04:01

Jackie Cheng


1 Answers

Instead of turning off instant run we can resolve this issue by utilising synthetic modifier check. 'com.android.tools.fd.runtime.IncrementalChange' is synthetic so we can check whether the field is synthetic using isSynthetc method.

Field[] fields = objClass.getFields();
for (Field field : fields) {
            String name = field.getName();
            Object value;

            if(field.isSynthetic()){
                continue;
            }
          //add your code here
            }
like image 197
diordna Avatar answered Nov 25 '22 12:11

diordna