Skip to content

sebhoss/generic-types

Repository files navigation

Generic Types Discuss on Google Groups Chat on IRC

CC Zero Maven Central Read JavaDocs Repository size Open Hub statistics

Build Status Code Coverage Coverity Scan Result Codacy Code Quality Can this project be forked? Is this thing still maintained? Bounties on open tickets

This Java library provides a factory to create generic java.lang.reflect.Type variations, such as Map<Number, Point>.

Features

  • Factory methods to create generic types, including wildcards.

Development Status

All currently required feature are implemented. This project is in maintenance mode.

Usage

// 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)));

Integration

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.

Compatibility

This project is compatible with the following Java versions:

Table 1. Java compatibility
1.X.Y 2.X.Y

Java 8

License

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/.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published