Redundant generated code in generic class on Android

Here’s a very simple generic class in RO C#:

public class TestClass<T>{
    public bool test(T value){    
        return value != null;
    }
}

Then after it’s compiled in release mode, I decompile the apk to check the generated java codes:

public class TestClass<T>{
    public boolean test(T t) {
        return (!(t instanceof Object) ? null : (Object) t) != null;
    }
}

Why is there an instanceof operation??

Finally I make a same test in Android Studio and here’s the official compile result:

public class TestClass<T>{
    public boolean test(T value){    
        return value != null;
    }
}

Thanks, logged as bugs://74590

There’s a good reason for that, most of the time. In this case however there isn’t. Will fix.

bugs://74590 got closed with status fixed.

I’d like to learn more details of the good reason :slightly_smiling:

There’s an implied cast when you get a “T” on the other side, becuase the real type is the generic base type (generally Object).

Logged as bugs://i62644.

bugs://i62644 was closed as fixed.