https://github.com/phase/mirror
A Java library that makes reflection easy
https://github.com/phase/mirror
Last synced: 11 months ago
JSON representation
A Java library that makes reflection easy
- Host: GitHub
- URL: https://github.com/phase/mirror
- Owner: phase
- License: mit
- Created: 2015-02-16T20:58:25.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-14T18:37:33.000Z (almost 11 years ago)
- Last Synced: 2025-03-25T07:11:33.433Z (12 months ago)
- Language: Java
- Homepage:
- Size: 234 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mirror
A Java representation of jQuery, using Reflection to interact with things.
jQuery is used to interact with the DOM in JavaScript. Java doesn't have a DOM, so the next best thing was Reflection, which interacts with everything in Java.
I recently found out `$` could be used as an identifier in Java, and I immediately thought of jQuery. jQuery messes with the DOM, Relfection messes with Classes. Put two and two together and we've got mirror!
##Use
The first thing you want to do is statically import Mirror.java:
```java
import static mirror.Mirror;
```
`$()` is the main method for mirror. It will get the class of what you input.
```java
int i = 7;
$(i); //returns a ReflectedClass of type Integer
$(i).print(); //prints 'java.lang.Integer'
```
All of the classes implement a Printable interface, so you can put `print()` anywhere in your chain to debug.
To invoke a method:
```java
String s = "Hello World";
String[] a = $(s).getMethod("split", String.class).invoke(" "); //returns s.split(" ")
```
You can also set and get fields:
```java
String s = "Hello World";
$(s).setField("hash", -5);
int i = $(s).getField("hash");
```