-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathReflectionUtils.java
More file actions
35 lines (32 loc) · 1.07 KB
/
ReflectionUtils.java
File metadata and controls
35 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.not2excel.api.reflection;
import java.lang.reflect.Field;
/**
* @author Richmond Steele
* @since 12/17/13
* All rights Reserved
* Please read included LICENSE file
*/
public class ReflectionUtils
{
public static Object getField(Object object, String field)
throws SecurityException, NoSuchFieldException,
IllegalArgumentException, IllegalAccessException
{
Class<?> c = object.getClass();
Field objectField = c.getDeclaredField(field);
objectField.setAccessible(true);
Object result = objectField.get(object);
objectField.setAccessible(false);
return result;
}
public static Method copyMethod(Method toCopy){
try{
Method copyMethod = Method.class.getDeclaredMethod("copy", (Class<?>[])null);
copyMethod.setAccessible(true);
return (Method) copyMethod.invoke(toCopy, (Object[]) null);
}catch(Exception e){
System.out.println("Exception while copying Method '" + toCopy.getName() + "'. Returning the method passed in arguments.");
return toCopy;
}
}
}