I tend to name such an item a "cursor position" as termed in ListIterator; I used the same term for Label in the ClassFile API. I indeed think this API would be useful: List.add, List.listIterator, TypeDescriptor.OfMethod.insertParameterTypes, getting labels in a code array for class files...
________________________________ From: core-libs-dev <[email protected]> on behalf of Kevin Bourrillion <[email protected]> Sent: Monday, January 13, 2025 2:19 PM To: Glavo <[email protected]> Cc: core-libs-dev <[email protected]> Subject: Re: Request for Enhancement: Objects.checkPositionIndex(int, int) Oh hey, I named those Guava methods. :-) This was my attempt to promote the terms “position indexes vs. element indexes” and hope that the idea caught on... which I’d say it still never has. I’m surprised you even noticed the methods. The notion is that “element indexes” are the buckets and “position indexes” are the possible insertion points between buckets. I personally find it simpler to think of a method like `subList` as simply accepting two position indexes, rather than thinking about half-open ranges. To me this was clarifying, but for people who never have this explained to them it’s probably not that clear. And basically, the adoption counts for those methods always remained very low. And I remember seeing a number of misuses, too. Not sure what to make of all this; just adding some context. On Jan 13, 2025, at 11:36 AM, Glavo <[email protected]> wrote: Currently the java.util.Objects provide the method `checkIndex(int, int)` for checking indexes. It is convenient, but cannot be used to implement methods such as List::add(int, E) because these methods accept an index pointing to the end of the collection. So is it possible to add a new method to Objects to check this kind of index? This is useful for implementing collections. (The checkPositionIndex in the title is its name in guava. I don't like the name, but I don't have a better idea.) Glavo
