Skip to content

Commit 9384f7f

Browse files
committed
merged
2 parents 5247b42 + f70a16e commit 9384f7f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

tests/isolated/FieldReflection.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import java.lang.reflect.Method;
22
import java.lang.reflect.Field;
3+
import java.util.Arrays;
4+
import java.util.Comparator;
35

46
public class FieldReflection {
57
public int a;
@@ -27,6 +29,7 @@ public static void main(String[] args) throws Exception {
2729
FieldReflection aaa = new FieldReflection(1534,2);
2830
Class cls = aaa.getClass();
2931
Field[] f = cls.getDeclaredFields();
32+
Arrays.sort(f, new FieldComparator());
3033
System.out.println(f.length);
3134
for (Field fld : f) {
3235
System.out.println(fld.getName());
@@ -70,4 +73,11 @@ public static void main(String[] args) throws Exception {
7073
static class FieldReflectionGen<T> {
7174
T[] arr;
7275
}
76+
77+
public static class FieldComparator implements Comparator<Field> {
78+
public int compare(Field f1, Field f2) {
79+
return f1.getName().compareTo(f2.getName());
80+
}
81+
82+
}
7383
}

tests/isolated/MethodReflection.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import java.lang.reflect.Method;
22
import java.lang.reflect.Type;
3+
import java.util.Arrays;
4+
import java.util.Comparator;
35

46
class MethodReflection {
57

68
public static void main(String[] args) throws Exception {
79
MethodReflection mr = new MethodReflection();
810
Class cls = mr.getClass();
11+
MethodComparator mc = new MethodComparator();
912
Method[] m = cls.getDeclaredMethods();
13+
Arrays.sort(m, mc);
1014
for (Method mtd : m) {
1115
if (mtd.getName().equals("<init>")) continue;
1216
System.out.println(mtd.getName());
@@ -26,4 +30,12 @@ public String ll(String s) {
2630
return "Called LL with "+s;
2731
}
2832

29-
}
33+
public static class MethodComparator implements Comparator<Method> {
34+
35+
public int compare(Method m1, Method m2) {
36+
return m1.getName().compareTo(m2.getName());
37+
}
38+
39+
}
40+
41+
}

0 commit comments

Comments
 (0)