in C#
class ListMap<K, E>
: ImyMap<K, E>, IComparable<K>, IEnumerable<KeyValuePair<K, E>>
{
}
in Java
class MyListMap<K extends Comparable<? super K>, E>
implements MyMap<K,E>, Iterable<KeyValuePair<K, E>>
{
}
Just trying to convert some data structures from Java into C# and wanted to know if my C# implementation is equal to my Java one.
If not can you please correct it?
No, those are not equal. The
K extends ...portion needs to be translated into a constraint:The wildcard
? super Kis not necessary in C#. Wildcards are Java’s way to support co/contravariance. In C#, this is done as part of the interface declaration:The
inmodifier makes the interface contravariant, which has the same effect as the wildcard in Java.