JEP draft: Scope Locals
Andrew Haley
aph at redhat.com
Fri May 14 08:31:12 UTC 2021
On 5/13/21 6:28 PM, Douglas Surber wrote:
> In most of you examples the ScopeLocal could easily be replaced with a local variable.
>
> record Point(int x, int y) {}
> static final ScopeLocal<Point> position = ScopeLocal.forType(Point.class);
>
> {
> ScopeLocal.where(position, new Point(33, 66),
> () -> System.out.println(position.get().x()));
> }
>
> could be written as
>
> record Point(int x, int y) {}
>
> {
> Point position = new Point(33, 66);
> System.out.println(position.x()));
> }
>
> This works even if code that uses position is a lambda. This made the value of ScopeLocals unclear.
It's just an example of the syntax. Would it help if I said that the
ScopeLocal.get() was buried many levels deep, not explicit as here?
> The CREDENTIALS example though does show the value of ScopeLocals, that CREDENTIALS can be dereferenced in the method connectDatabase() which is outside the lexical scope where creds is defined. It would help if the first example was along this line and clearly called out how a ScopeLocal (really a DynamicScopeLocal) is different from a lexically scoped local variable.
I see. OK.
--
Andrew Haley (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the loom-dev
mailing list