RFR: 8287834: Add SymbolLookup::or method

Paul Sandoz psandoz at openjdk.org
Tue May 16 16:53:45 UTC 2023


On Fri, 12 May 2023 12:11:23 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`.

src/java.base/share/classes/java/lang/foreign/SymbolLookup.java line 136:

> 134:      * lookup} More specifically, if a symbol is not found using this lookup, the provided lookup will be
> 135:      * used as fallback. In other words, the resulting symbol lookup will only return {@linkplain Optional#empty()}
> 136:      * if both lookups fail to retrieve a given symbol.

Suggestion:

     * {@return a composed symbol lookup that returns result of finding the symbol with this lookup if found, otherwise returns the result of finding the symbol with the other lookup.}

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13954#discussion_r1195440611


More information about the core-libs-dev mailing list