Forum Xamarin.Android

LoaderManager.ILoaderCallbacks missing generic type parameter?

fljohwatfljohwat USMember
edited October 2012 in Xamarin.Android

I am trying to use the AsyncTaskLoader, by basing my Activity on an FragmentActivity, and using Android.Support.V4.App.
However, the way this is declared in Mono, I end up declaring my interface as such
public class OutNAboutActivity : FragmentActivityBase, LoaderManager.ILoaderCallbacks
I was hoping to do
public class OutNAboutActivity : FragmentActivityBase, LoaderManager.ILoaderCallbacks, i.e. with a type parameter, which Java has…
Without it, my interface gets passed Java.Lang.Object parameters, which don’t do me much good…


  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    Unfortunately, Java generics don't really exist, not at the bytecode level, not like in .NET. Consequently, the generated bindings don't "see" generic type parameters (they don't exist), and all bound types use e.g. Java.Lang.Object, because that's what the bytecode uses (because type parameters don't exist). See also my epic comparison between Java and C# generics.

    When there are generic types, e.g. AsyncTask<TParams, TProgress, TResult>, it's because we created that type by hand, not by auto-generated tooling, and we only did this for the more common types.

    Unfortunately this means that you're going to need to use Java.Lang.Object parameters, and you'll just need to .JavaCast<T>() them to appropriate types.

  • fljohwatfljohwat USMember

    And going back from a .NET type to a Java.Lang.Object... (needed when the loader returns it's results).?
    Is there a chance that these 'missing' types will be added in the future manually? It would seem quite helpful.

Sign In or Register to comment.