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

17
LINES

< > BotCompany Repo | #1035085 // getDeclaredConstructors_cached - also calls setAccessible(true) on all constructors

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

Libraryless. Click here for Pure Java version (7652L/43K).

1  
scope getDeclaredConstructors_cached
2  
3  
// TODO: convert to regularly cleared normal map
4  
static Map<Class, Constructor[]> #cache = newDangerousWeakHashMap();
5  
6  
static Constructor[] getDeclaredConstructors_cached(Class c) {
7  
  Constructor[] ctors;
8  
  synchronized(cache) {
9  
    ctors = cache.get(c);
10  
    if (ctors == null) {
11  
      cache.put(c, ctors = c.getDeclaredConstructors());
12  
      for (ctor : ctors)
13  
        makeAccessible(ctor);
14  
    }
15  
  }
16  
  ret ctors;
17  
}

Author comment

Began life as a copy of #1005587

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1035085
Snippet name: getDeclaredConstructors_cached - also calls setAccessible(true) on all constructors
Eternal ID of this version: #1035085/3
Text MD5: 70872e836c20d8a7a31f2b33e5c4013a
Transpilation MD5: fe17949d12bb1f144343936e5a56fe68
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-02 18:06:40
Source code size: 470 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 160 / 235
Version history: 2 change(s)
Referenced in: [show references]