This library contains utility classes related to reflection.
I found myself re-implementing these type of methods over and over again
whenever I needed reflection in some project.
As there seldom is enough time to do this properly and take things like caching
into consideration, the solutions were always sub-optimal.
That is why this library was created.
Have you found a bug? Did you create new featue?
Please see the contributing page for more information.
For getting or finding classes and interacting with them.
The difference between getting and finding is that a get
operation
throws exceptions if nothing is found, and find
returns null
.
For getting or finding methods and invoking them.
For getting or finding constructors and invoking them.
Containing the BeanReflection
class, this package provides access to
Java's built-in Introspector.getBeanInfo
but falls back to public field access
when available.
Furthermore, the properties can be 'chained' safely concatenating them
with dots inbetween ('.'
). Array indices are also supported by square brackets ('['
and ']'
).
The AbstractDto
superclass can be extended when your class is merely a Data Transfer Object.
Such DTO's are all about simply representing a datastructure and normally don't need any methods.
Subclasses merely need to provide public fields containing their datastructure
and will be automatically provided with equals
, hashCode
, toString
and clone
implementations including all accessible fields from the subclass.
The ToStringBuilder
is a convenient builder for toString()
representations
containing named field appenders. It is part of the reflection library because
it can easily be instantiated for any bean by the static reflect
method.
Contains the exception types that can be thrown by this library,
all subclasses of java.lang.RuntimeException
.
If you're using the Java 9 module system (e.g. project jigsaw),
you can still use this reflection library. Actually the library itself is
neatly published as a java 9 module called nl.talsmasoftware.reflection
even though the classes are still java 5 binary compatible.
However, out of the box, our module cannot reflect your classes if you haven't opened them up.
So be sure to either declare your module as an open
module or explicitly open up a
package for reflection by this module.
Prepend your module with the open
keyword to open it up for reflection like this:
open module com.example.myapp {
requires nl.talsmasoftware.reflection;
}
Or you can define a specific package for reflection:
module com.example.myapp {
opens com.example.myapp.dto to nl.talsmasoftware.reflection;
requires nl.talsmasoftware.reflection;
}