Skip to content

Commit 1598623

Browse files
Caching class names (0.6)
Now caching the various class names rather than retrieving them every time (it can make a big difference) Fixed BetterReflectionClass#getSuperClass() Bumped version to 0.6
1 parent 2d3d0f7 commit 1598623

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

Java-BetterReflection/src/me/wavelength/betterreflection/BetterReflection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public Boolean call() throws Exception {
152152
* @since 0.4
153153
*/
154154
public static final String getVersion() {
155-
return "0.5";
155+
return "0.6";
156156
}
157157

158158
/**

Java-BetterReflection/src/me/wavelength/betterreflection/BetterReflectionClass.java

+40-11
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,36 @@
1010

1111
public class BetterReflectionClass {
1212

13+
/**
14+
* @since 0.6
15+
*/
16+
private final String name;
17+
/**
18+
* @since 0.6
19+
*/
20+
private final String simpleName;
21+
/**
22+
* @since 0.6
23+
*/
24+
private final String canonicalName;
25+
/**
26+
* @since 0.6
27+
*/
28+
private final String typeName;
29+
1330
private Class<?> clasz;
1431

15-
private Field[] declaredFields;
16-
private Field[] fields;
17-
private Constructor<?>[] declaredConstructors;
18-
private Constructor<?>[] constructors;
19-
private Method[] declaredMethods;
20-
private Method[] methods;
32+
private final Field[] declaredFields;
33+
private final Field[] fields;
34+
private final Constructor<?>[] declaredConstructors;
35+
private final Constructor<?>[] constructors;
36+
private final Method[] declaredMethods;
37+
private final Method[] methods;
2138

22-
private Class<?> superClass;
39+
/**
40+
* @since 0.6
41+
*/
42+
private final Class<?> superClass;
2343

2444
public BetterReflectionClass(String className) throws ClassNotFoundException {
2545
this(Class.forName(className));
@@ -28,12 +48,18 @@ public BetterReflectionClass(String className) throws ClassNotFoundException {
2848
public BetterReflectionClass(Class<?> clasz) {
2949
this.clasz = clasz;
3050

51+
this.name = clasz.getName();
52+
this.simpleName = clasz.getSimpleName();
53+
this.canonicalName = clasz.getCanonicalName();
54+
this.typeName = clasz.getTypeName();
55+
3156
this.declaredFields = clasz.getDeclaredFields();
3257
this.fields = clasz.getFields();
3358
this.declaredConstructors = clasz.getDeclaredConstructors();
3459
this.constructors = clasz.getConstructors();
3560
this.declaredMethods = clasz.getDeclaredMethods();
3661
this.methods = clasz.getMethods();
62+
this.superClass = clasz.getSuperclass();
3763
}
3864

3965
/**
@@ -57,28 +83,28 @@ public Class<?> getClasz() {
5783
* @since 0.4
5884
*/
5985
public String getName() {
60-
return clasz.getName();
86+
return name;
6187
}
6288

6389
/**
6490
* @since 0.4
6591
*/
6692
public String getSimpleName() {
67-
return clasz.getSimpleName();
93+
return simpleName;
6894
}
6995

7096
/**
7197
* @since 0.4
7298
*/
7399
public String getCanonicalName() {
74-
return clasz.getCanonicalName();
100+
return canonicalName;
75101
}
76102

77103
/**
78104
* @since 0.4
79105
*/
80106
public String getTypeName() {
81-
return clasz.getTypeName();
107+
return typeName;
82108
}
83109

84110
public Field getDeclaredField(String name) {
@@ -230,6 +256,9 @@ public Object invokeMethod(Object instance, String methodName, Object... paramet
230256
return getMethod(methodName, BetterReflectionUtils.getTypes(parameters)).invoke(instance, parameters);
231257
}
232258

259+
/**
260+
* @since 0.6
261+
*/
233262
public Class<?> getSuperclass() {
234263
return superClass;
235264
}

0 commit comments

Comments
 (0)