mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-12-03 02:13:22 +01:00
Add ReflectionUtils
This commit is contained in:
parent
6e76f07876
commit
640c986e2f
@ -0,0 +1,36 @@
|
||||
package de.epiceric.shopchest.nms;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Reflection utility class
|
||||
*/
|
||||
public class ReflectionUtils {
|
||||
|
||||
/**
|
||||
* Unsafe cast, used to suppress warning for known type of generic class
|
||||
*
|
||||
* @param o The object to cast
|
||||
* @param <T> The type you want
|
||||
* @return The same object but with the good type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T forceCast(Object o) {
|
||||
return (T) o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a private static field value
|
||||
*
|
||||
* @param clazz The {@link Class} to lookup
|
||||
* @param fieldName The {@link Field} name
|
||||
* @return The value the private static field
|
||||
* @throws ReflectiveOperationException If the field can't be found
|
||||
*/
|
||||
public static Object getPrivateStaticFieldValue(Class<?> clazz, String fieldName) throws ReflectiveOperationException {
|
||||
final Field field = clazz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field.get(null);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user