Libraryless. Click here for Pure Java version (7541L/43K).
1 | static Map<Class, Constructor> nuObjectWithoutArguments_cache = newDangerousWeakHashMap(); |
2 | |
3 | static O nuObjectWithoutArguments(S className) ctex {
|
4 | ret nuObjectWithoutArguments(classForName(className)); |
5 | } |
6 | |
7 | static <A> A nuObjectWithoutArguments(Class<A> c) ctex {
|
8 | if (nuObjectWithoutArguments_cache == null) |
9 | // in class init |
10 | ret (A) nuObjectWithoutArguments_findConstructor(c).newInstance(); |
11 | |
12 | Constructor m = nuObjectWithoutArguments_cache.get(c); |
13 | if (m == null) |
14 | nuObjectWithoutArguments_cache.put(c, m = nuObjectWithoutArguments_findConstructor(c)); |
15 | return (A) m.newInstance(); |
16 | } |
17 | |
18 | static Constructor nuObjectWithoutArguments_findConstructor(Class c) {
|
19 | for (Constructor m : getDeclaredConstructors_cached(c)) |
20 | if (empty(m.getParameterTypes())) {
|
21 | makeAccessible(m); |
22 | ret m; |
23 | } |
24 | fail("No default constructor found in " + c.getName());
|
25 | } |
Began life as a copy of #1001136
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: | #1008660 |
| Snippet name: | nuObjectWithoutArguments |
| Eternal ID of this version: | #1008660/11 |
| Text MD5: | 16af5afd895104e026f270024a5132f9 |
| Transpilation MD5: | a1d702df2b4e3c0d797836917ef9e947 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-03-29 19:42:35 |
| Source code size: | 903 bytes / 25 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 883 / 1043 |
| Version history: | 10 change(s) |
| Referenced in: | [show references] |