The MonoTouch documentation states that it doesn’t support virtual generic methods.
However, in my MonoTouch project I have the classes
public class ListMaker<T>
{
public ListMaker() {}
public virtual List<T> MakeList(T t1, T t2)
{
return new List<T>{t1, t2};
}
}
public class ReverseListMaker<T> : ListMaker<T>
{
public ReverseListMaker() {}
public override List<T> MakeList(T t1, T t2)
{
return new List<T>{t2, t1};
}
}
and elsewhere…
ListMaker<string> lm = new ReverseListMaker<string>();
List<string> strings = lm.MakeList("hello", "world");
Now, my expectation is that this shouldn’t compile. However, it is compiling and running on the iOS simulator.
Does the limitation apply only to the actual ARM architecture of the devices? Or is the documentation outdated?
Short answers:
Yes
No
Long answer:
Most of the MonoTouch limitations are dictated by the rules that all applications must follow to run on iOS devices.
That includes some limitations on generic because the AOT (ahead-of-time) compiler cannot know every possible cases for which code needs to be generated.
However since the rules applies only to device and that AOT compilation takes quite some time, MonoTouch will use the JIT (just-in-time) compiler when used on the simulator. This allows faster code-build-debug cycles and makes development much more enjoyable. The downside is that this can hides a few limitations (like the AOT ones).
Nevertheless there are many situations where the iOS simulator behaves very differently than the devices. IOW something that works on the simulator does not mean it will work (at least as nicely or at all) on devices. As such all (or most) testing should be done on (if possible many different) devices.