On Fri, 23 Apr 2021 at 23:07, Brian Goetz <brian.go...@oracle.com> wrote: > >> Is there a compelling example of where this would be used by clients? > > Here are some examples: > > https://stackoverflow.com/questions/10988634/java-global-isempty-method > Without passing judgment on the sort of dynamically typed programs that > need a method like this
The other example is better as it benefits from declaring an API that only accepts instances of `Sized` and does not need to get the contents. > But again, if you are treating these things as containers, then a Sized > doesn't get you very far, because if you conclude the thing isn't empty, > you're going to want to get stuff out, and Sized has no methods for > that. So presumably there's some companion to Sized for accessing > elements by index: > > interface HasStuff<T> extends Sized { > T get(int index); > } I don't think there has to be. the more useful interface would be this one, but to date there has been strong resistance in unifying the Collection and Map interfaces: interface Stuff<T> extends Sized { int size(); int isEmpty(); int isNotEmpty(); Iterator<t> iterator(); } Stephen