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


< > BotCompany Repo | #1001137 // findClass

JavaX fragment (include)

static new HashMap<S, Class> findClass_cache;

// currently finds only inner classes of class "main"
// returns null on not found
// this is the simple version that is not case-tolerant
static Class findClass(String name) {
  synchronized(findClass_cache) {
    if (findClass_cache.containsKey(name))
      ret findClass_cache.get(name);
    if (!isJavaIdentifier(name)) ret null;
    Class c;
    try {
      c = Class.forName("main$" + name);
    } catch (ClassNotFoundException e) {
      c = null;
    findClass_cache.put(name, c);
    ret c;

Author comment

The cache can contain null values - it's a very important optimization if you look for non-existing classes a lot (e.g. when loading foreign concepts without having the custom classes).

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001137
Snippet name: findClass
Eternal ID of this version: #1001137/1
Text MD5: d75ff28f0ae40817234f1333213d4585
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-29 15:18:23
Source code size: 591 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 685 / 4527
Referenced in: [show references]