This Java library provides a factory to create generic java.lang.reflect.Type
variations, such as Map<Number, Point>
.
All currently required feature are implemented. This project is in maintenance mode.
// Map<Number, Point>
final Type type = GenericTypes.generic(Map.class, Number.class, Point.class);
// List<Number>
final Type type = GenericTypes.generic(List.class, Number.class);
Super- and subtypes such as List<? super Point>
or List<? extends Number>
can be created in the following way:
// List<? super Point>
final Type type = GenericTypes.generic(List.class, GenericTypes.supertype(Point.class));
// List<? extends Number>
final Type type = GenericTypes.generic(List.class, GenericTypes.subtype(Number.class));
Use static imports to shorten the above calls to:
// List<? super Point>
final Type type = generic(List.class, supertype(Point.class));
// List<? extends Number>
final Type type = generic(List.class, subtype(Number.class));
and then go crazy with this:
// List<Map<? extends Number, ? super Point>>
final Type type = generic(List.class, generic(Map.class, subtype(Number.class), supertype(Point.class)));
To use this project just declare the following dependency inside your POM:
<dependencies>
<dependency>
<groupId>de.xn--ho-hia.utils.types</groupId>
<artifactId>generic-types</artifactId>
<version>${version.generic-types}</version>
</dependency>
</dependencies>
Replace ${version.generic-types}
with the latest release. This project follows the semantic versioning guidelines.
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.