-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'nea89o-highlightthingy'
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.torui.coflsky.utils; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.reflect.Field; | ||
import java.util.Arrays; | ||
|
||
public class ReflectionUtil { | ||
|
||
public static MethodHandle getField(Class<?> clazz, String... names) { | ||
Field f = null; | ||
for (String name : names) { | ||
try { | ||
f = clazz.getDeclaredField(name); | ||
break; | ||
} catch (NoSuchFieldException e) { | ||
} | ||
} | ||
if (f == null) | ||
throw new RuntimeException("Could not find any of fields " + Arrays.toString(names) + " on class " + clazz); | ||
f.setAccessible(true); | ||
try { | ||
return MethodHandles.publicLookup().unreflectGetter(f); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |