Hello,
the problem with java.util.List (unlike say Runtime.Version or Optional#get) is 
that List is *both* used directly and implemented.

For users, it is clear that removeAtIndex() should be used.

For implementors of java.util.List, it is not clear how to guarantee that 
remove(index) and removeAtIndex() are always in sync,
especially because most of the named implementation of java.util.List can be 
inherited.

We do not want to be in a situation where remove(index) and removeAtIndex() 
have two different implementations.

So I think it's premature to create a PR until we discuss what can be 
done/should be done to solve that problem.

Should we changed the tooling (javac, IDEs?) so implementation drift are 
recognized and reported ?
Are there other solutions ?

regards,
Rémi

----- Original Message -----
> From: "Per Minborg" <[email protected]>
> To: "core-libs-dev" <[email protected]>
> Sent: Thursday, May 7, 2026 10:19:39 AM
> Subject: RFR: 8384062: Add a new method List::removeAtIndex to avoid overload 
> confusion

> This PR proposes to add a new `default` method `List::removeAtIndex`.
> 
> There are two overloads of the method `List::remove`, and if the list is of 
> type
> `List<Integer>`, the overload resolution could pick a surprising variant.
> 
> Hence, it is better to add a separate method that removes an element based on
> its index.
> 
> It is proposed that the `E remove(int index)` method is _not_ `@Deprecated`.
> Instead, we add verbiage to promote the new method over the old one.
> 
> ---------
> - [X] I confirm that I make this contribution in accordance with the [OpenJDK
> Interim AI Policy](https://openjdk.org/legal/ai).
> 
> -------------
> 
> Commit messages:
> - Add List::removeAtIndex
> 
> Changes: https://git.openjdk.org/jdk/pull/31064/files
>  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=31064&range=00
>  Issue: https://bugs.openjdk.org/browse/JDK-8384062
>  Stats: 75 lines in 2 files changed: 70 ins; 0 del; 5 mod
>  Patch: https://git.openjdk.org/jdk/pull/31064.diff
>  Fetch: git fetch https://git.openjdk.org/jdk.git pull/31064/head:pull/31064
> 
> PR: https://git.openjdk.org/jdk/pull/31064

Reply via email to