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

14
LINES

< > BotCompany Repo | #1033721 // WeakVar - Var using a weak reference

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

Libraryless. Click here for Pure Java version (4566L/25K).

sclass WeakVar<A> implements IVar<A> {
  WeakReference<A> ref;
  
  public synchronized void set(A a) {
    ref = weakRef(a);
  }
  
  public synchronized A get() {
    if (ref == null) null;
    A value = ref!;
    if (value == null) ref = null;
    ret value;
  }
}

Author comment

Began life as a copy of #1033409

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033721
Snippet name: WeakVar - Var using a weak reference
Eternal ID of this version: #1033721/3
Text MD5: 6af7f86cc5cf92d8052195bcd73344ba
Transpilation MD5: 9faad8f53f71bdac7b4a6bebb34fce56
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-28 22:00:08
Source code size: 280 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 189 / 299
Version history: 2 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)