Search code examples
android-studiopojo

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 ?


Solution

  • 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
                }