1 | static Field findField(Object o, String field) {
|
2 | if (o instanceof Class) return findField_static((Class) o, field); |
3 | |
4 | Class c = o.getClass(); |
5 | for (Field f : c.getDeclaredFields()) |
6 | if (f.getName().equals(field)) |
7 | return f; |
8 | throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
|
9 | } |
10 | |
11 | static Field findField_static(Class<?> c, String field) {
|
12 | for (Field f : c.getDeclaredFields()) |
13 | if (f.getName().equals(field) && (f.getModifiers() & Modifier.STATIC) != 0) |
14 | return f; |
15 | throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
|
16 | } |
Began life as a copy of #1000619
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000799 |
| Snippet name: | findField function |
| Eternal ID of this version: | #1000799/1 |
| Text MD5: | 4446366abd7c61cc63723b4fc2158548 |
| Author: | stefan |
| Category: | |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-28 16:05:35 |
| Source code size: | 626 bytes / 16 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 1146 / 1389 |
| Referenced in: | [show references] |