3 ms·
I think your comment is a bit… not sure what the word is, under-appreciating the feature? Over-selling some languages? Because AFAIK Java (or C#?) does not hav
by masklinn 9y ago
I think your comment is a bit… not sure what the word is, under-appreciating the feature? Over-selling some languages?
Because AFAIK Java (or C#?) does not have constrained interface conformance, it only has bounds on functions (which Swift already had). That is you can say
static <T extends Comparable<? super T>> void sort(MyList<T> list)
such that you can only sort lists of comparables, but you can't say
class MyList implements Comparable<T extends Comparable<? super T>>
such that MyList implements comparable IIF its items are comparable.
- dahauns 9y agoAgh, yes. I already regret putting Java in that list with its wonky implementation. :) But it certainly works with others, e.g. something like this: public class SortedList<T> : ICollection<T>,IEnumerable<T> where T : IComparable<T>
- masklinn 9y agoIs that C#? So it does have optional interface implementation? TIL.
- dahauns 9y agoHuh? I'm not sure where you're getting at.
- masklinn 9y agoI'm only asking if the snippet you posted is C# or something else, and noting that if it's C# I have learned something new about the language. Except now that I look at it more specifically, it looks like a bound on the class's generic parameter rather than a condition on the interface implementation? As in you're defining a SortedList class which implements ICollection and IEnumerable but requires T:IComparable, not defining a SortedList class which implements IEnumerable if T is IComparable. And if that reading is correct, Java can do it just fine: class SortedList<T extends Comparable<T>> implements Collection<T>, Iterable<T> however it's got nothing to do with conditional conformance.