-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of Class.getDeclaringClass()
- Loading branch information
1 parent
452133c
commit 2f4bac0
Showing
18 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package samples.reflection.trivial.classgetdeclaringclassexample; | ||
|
||
public class GetDeclaringClassExample { | ||
public static class TopLevel { | ||
} | ||
|
||
public static class SimpleNested { | ||
public class Inner { | ||
} | ||
|
||
public static class StaticNested { | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
print(double.class); | ||
|
||
print(String[].class); | ||
|
||
print(GetDeclaringClassExample.class); | ||
|
||
print(TopLevel.class); | ||
|
||
print(SimpleNested.Inner.class); | ||
|
||
print(SimpleNested.StaticNested.class); | ||
|
||
Runnable anonymous = new Runnable() { | ||
@Override | ||
public void run() { | ||
} | ||
}; | ||
print(anonymous.getClass()); | ||
|
||
class LocalClass { | ||
} | ||
print(LocalClass.class); | ||
|
||
testStaticMethodInner(); | ||
|
||
DeepNesting outer = new DeepNesting(); | ||
DeepNesting.Inner inner = outer.new Inner(); | ||
DeepNesting.Inner.DeepInner deepInner = inner.new DeepInner(); | ||
print(DeepNesting.Inner.class); | ||
print(DeepNesting.Inner.DeepInner.class); | ||
print(deepInner.getClass()); | ||
|
||
// Runnable lambda = () -> { | ||
// }; | ||
// print(lambda.getClass()); // Execution Error: Unknown reference opcode: 186 | ||
} | ||
|
||
private static void testStaticMethodInner() { | ||
class StaticMethodInner { | ||
} | ||
print(StaticMethodInner.class); | ||
} | ||
|
||
static class DeepNesting { | ||
public class Inner { | ||
public class DeepInner { | ||
} | ||
} | ||
} | ||
|
||
private static void print(Class<?> clazz) { | ||
System.out.print(clazz.getName()); | ||
System.out.print(": "); | ||
System.out.println(clazz.getDeclaringClass()); | ||
} | ||
|
||
} |
Binary file added
BIN
+554 Bytes
...samples/reflection/trivial/classgetdeclaringclassexample/GetDeclaringClassExample$1.class
Binary file not shown.
Binary file added
BIN
+506 Bytes
...flection/trivial/classgetdeclaringclassexample/GetDeclaringClassExample$1LocalClass.class
Binary file not shown.
Binary file added
BIN
+512 Bytes
...n/trivial/classgetdeclaringclassexample/GetDeclaringClassExample$1StaticMethodInner.class
Binary file not shown.
Binary file added
BIN
+835 Bytes
.../classgetdeclaringclassexample/GetDeclaringClassExample$DeepNesting$Inner$DeepInner.class
Binary file not shown.
Binary file added
BIN
+829 Bytes
...on/trivial/classgetdeclaringclassexample/GetDeclaringClassExample$DeepNesting$Inner.class
Binary file not shown.
Binary file added
BIN
+563 Bytes
...flection/trivial/classgetdeclaringclassexample/GetDeclaringClassExample$DeepNesting.class
Binary file not shown.
Binary file added
BIN
+698 Bytes
...n/trivial/classgetdeclaringclassexample/GetDeclaringClassExample$SimpleNested$Inner.class
Binary file not shown.
Binary file added
BIN
+580 Bytes
...al/classgetdeclaringclassexample/GetDeclaringClassExample$SimpleNested$StaticNested.class
Binary file not shown.
Binary file added
BIN
+702 Bytes
...lection/trivial/classgetdeclaringclassexample/GetDeclaringClassExample$SimpleNested.class
Binary file not shown.
Binary file added
BIN
+436 Bytes
.../reflection/trivial/classgetdeclaringclassexample/GetDeclaringClassExample$TopLevel.class
Binary file not shown.
Binary file added
BIN
+2.74 KB
...a/samples/reflection/trivial/classgetdeclaringclassexample/GetDeclaringClassExample.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters