RFR: 8287834: Add SymbolLookup::or method [v3]

John Hendrikx jhendrikx at openjdk.org
Wed May 17 01:33:55 UTC 2023


On Tue, 16 May 2023 22:36:51 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This patch adds a simpler method for composing symbol lookups. It is common for clients to chain multiple symbol lookups together, e.g. to find a symbol in multiple libraries.
>> 
>> A new instance method, namely `SymbolLookup::or` is added, which first searches a symbol in the first lookup, and, if that fails, proceeds to search the symbol in the provided lookup.
>> 
>> We have considered alternatives to express this, such as a static factory `SymbolLookup::ofComposite` but settled on this because of the similarity with `Optional::or`.
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Tweak javadoc

Isn't it already possible to easily create a composed `SymbolLookup`?

     SymbolLookup lookUp = name -> library1.find(name)
          .or(() -> library2.find(name))
          .or(() -> loader.find(name));

The proposed method may be a bit nicer, but it is sort of duplicating what `Optional::or` was intended for.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/13954#issuecomment-1550560151


More information about the core-libs-dev mailing list