Bug 32314 - Java.Util.Collections.EmptyList() returns System.Collections.IList
Summary: Java.Util.Collections.EmptyList() returns System.Collections.IList
Status: RESOLVED ANSWERED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 5.1
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-07-22 12:24 UTC by Roy
Modified: 2015-07-23 14:50 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Roy 2015-07-22 12:24:36 UTC
Java.Util.Collections.EmptyList() returns a System.Collections.IList instead of a Java.Util.IList. The documentation at http://developer.xamarin.com/api/member/Java.Util.Collections.EmptyList() lists the link for the type IList three times, with two of them linking to Java.Util.IList, and one of them linking to System.Collections.IList.
Comment 1 Jonathan Pryor 2015-07-23 14:50:16 UTC
This is an unfortunate interaction between our binding algorithm and our documentation import algorithm.

It is (unfortunately) unlikely to be fixed, at least not anytime soon, in large part because I'm not sure what "fixing" it even looks like or means.

Firstly, there's the binding design principals:

http://developer.xamarin.com/guides/android/advanced_topics/api_design/#Design_Principles

> Conform to the .NET Framework Design Guidelines
> Utilize Framework Alternatives to Minimize Java Classlib exposure

For better or worse, the intent of those points is that Java methods that accept or return Java collection interfaces instead use corresponding .NET interfaces. The intent to this was to more easily permit using existing .NET code. For example, if you have a method which accepts IList or IList<T>, you can easily use that existing code without needing to manually create a wrapper instance or call an extension method; It Just Works™.

Consequently, the java.util.Collections.emptyList() method, which returns a java.util.List, is bound as returning a System.Collections.IList.

Secondly, our documentation import tool takes existing Javadoc links and maps them as closely as possible to the bound Xamarin.Android type. Since the Collections.emptyList() method documentation explicitly mentions the java.util.List type, the documentation import tool replaces these references with links to the Java.Util.IList type.

This can be fixed, but only with manual review, and with many thousands of bound types (and more thousands of methods) this isn't quite feasible for us.

Then there's the question of what to fix it *to*: the documentation, at present, is *correct*: while the return type is System.Collections.IList, the type returned *also* implements the Java.Util.IList interface, which can be obtained by e.g.:

    var list = Java.Util.Collections.EmptyList().JavaCast<Java.Util.IList>();