Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1016243 // tempSetField

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2887L/17K).

static AutoCloseable tempSetField(O o, S field, O value) {
  fO oldValue = get(o, field);
  set(o, field, value);
  ret () -> set(o, field, oldValue);
}

static <A> AutoCloseable tempSetField(ISetAndGet<A> gs, A value) {
  if (gs == null) null; // convenient null propagation as always in JavaX!
  A oldValue = gs!;
  gs.set(value);
  ret () -> gs.set(oldValue);
}

static <A> AutoCloseable tempSetField(A value, ISetAndGet<A> gs) {
  ret tempSetField(gs, value);
}

Author comment

Began life as a copy of #1012933

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1016243
Snippet name: tempSetField
Eternal ID of this version: #1016243/4
Text MD5: 1edc4a4d914a9d8a316bc247c21b371d
Transpilation MD5: 4622b6edd9324ef345a2002d1fea8360
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-22 07:50:05
Source code size: 480 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 338 / 421
Version history: 3 change(s)
Referenced in: [show references]