enable openhub
[generic-types.git] / README.asciidoc
blobb07054ebb711088dcde0042043cebc946b0d3143
1 = Generic Types
2 Sebastian Hoß <https://github.com/sebhoss[@sebhoss]>
3 :github-org: sebhoss
4 :project-name: generic-types
5 :project-group: com.github.sebhoss.utils
6 // :coverity-project: 2658
8 // image:https://img.shields.io/maven-central/v/{project-group}/{project-name}.svg?style=flat-square["Maven Central", link="https://maven-badges.herokuapp.com/maven-central/{project-group}/{project-name}"]
9 image:https://www.openhub.net/p/{project-name}/widgets/project_thin_badge.gif["Open Hub statistics", link="https://www.ohloh.net/p/{project-name}"]
10 image:https://img.shields.io/travis/{github-org}/{project-name}/master.svg?style=flat-square["Build Status", link="https://travis-ci.org/{github-org}/{project-name}"]
11 image:https://img.shields.io/coveralls/{github-org}/{project-name}/master.svg?style=flat-square["", link="https://coveralls.io/github/{github-org}/{project-name}"]
12 // image:https://scan.coverity.com/projects/{coverity-project}/badge.svg["Coverity Scan Result", link="https://scan.coverity.com/projects/{coverity-project}"]
13 // image:https://badges.gitter.im/Join%20Chat.svg["Gitter", link="https://gitter.im/{github-org}/{project-name}"]
15 This Java library provides a factory to create generic `java.lang.reflect.Type` variations, such as `Map<String, Object>`. Use it as follows:
17 [source,java]
18 ----
19 final Type genericMap = GenericTypes.generic(Map.class, String.class, Object.class);
20 final Type genericList = GenericTypes.generic(List.class, String.class);
21 ----
23 Super- and subtypes such as `List<? super Point>` or `List<? extends Number>` can be created in the following way:
25 [source,java]
26 ----
27 final Type list = GenericTypes.generic(List.class, GenericTypes.supertype(Point.class));
28 final Type list = GenericTypes.generic(List.class, GenericTypes.subtype(Number.class));
29 ----
31 Use static imports to shorten the above calls to:
33 [source,java]
34 ----
35 final Type list = generic(List.class, supertype(Point.class));
36 final Type list = generic(List.class, subtype(Number.class));
37 ----
39 and then go crazy with this:
41 [source,java]
42 ----
43 final Type type = generic(List.class, generic(Map.class, subtype(Number.class), supertype(String.class)));
44 ----
46 which represents a `List<Map<? extends Number, ? super String>>`.