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

29
LINES

< > BotCompany Repo | #1005305 // findField2 - goes to superclasses - uses getOpt's cache now for non-static fields

JavaX fragment (include)

please include function getOpt_cached.

static Field findField2(O o, S field) {
  Class c = o.getClass();
  HashMap<S, Field> map;
  synchronized(getOpt_cache) {
    map = getOpt_cache.get(c);
    if (map == null)
      map = getOpt_makeCache(c);
  }
  
  if (map == getOpt_special) {
    if (o instanceof Class)
      ret findField2_findStaticField((Class) o, field);
  }
    
  ret map.get(field);
}

static Field findField2_findStaticField(Class<?> c, String field) {
  Class _c = c;
  do {
    for (Field f : _c.getDeclaredFields())
      if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
        return f;
    _c = _c.getSuperclass();
  } while (_c != null);
  ret null;
}

Author comment

Began life as a copy of #1002772

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1005305
Snippet name: findField2 - goes to superclasses - uses getOpt's cache now for non-static fields
Eternal ID of this version: #1005305/5
Text MD5: b54c316abc3da883413c1e6d096e5ff6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-22 15:59:54
Source code size: 749 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 585 / 610
Version history: 4 change(s)
Referenced in: [show references]