Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan12 committed Nov 7, 2018
2 parents 5247b42 + f70a16e commit 9384f7f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/isolated/FieldReflection.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Comparator;

public class FieldReflection {
public int a;
Expand Down Expand Up @@ -27,6 +29,7 @@ public static void main(String[] args) throws Exception {
FieldReflection aaa = new FieldReflection(1534,2);
Class cls = aaa.getClass();
Field[] f = cls.getDeclaredFields();
Arrays.sort(f, new FieldComparator());
System.out.println(f.length);
for (Field fld : f) {
System.out.println(fld.getName());
Expand Down Expand Up @@ -70,4 +73,11 @@ public static void main(String[] args) throws Exception {
static class FieldReflectionGen<T> {
T[] arr;
}

public static class FieldComparator implements Comparator<Field> {
public int compare(Field f1, Field f2) {
return f1.getName().compareTo(f2.getName());
}

}
}
14 changes: 13 additions & 1 deletion tests/isolated/MethodReflection.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Comparator;

class MethodReflection {

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

}
public static class MethodComparator implements Comparator<Method> {

public int compare(Method m1, Method m2) {
return m1.getName().compareTo(m2.getName());
}

}

}

0 comments on commit 9384f7f

Please sign in to comment.