Skip to content
用Builder生成泛型,generics type builder
Java
Branch: master
Clone or download
ikidou Update WildcardTypeImpl.java
Correct a misspelling,suffix -> perfix
Latest commit 06df694 Jul 28, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea/copyright update .gitignore Sep 24, 2016
gradle/wrapper update .gitignore Sep 24, 2016
src Update WildcardTypeImpl.java Jul 28, 2017
.gitignore update .gitignore Sep 24, 2016
LICENSE init Jul 5, 2016
README.md update .gitignore Sep 24, 2016
build.gradle init Jul 5, 2016
gradlew init Jul 5, 2016
gradlew.bat
settings.gradle init Jul 5, 2016

README.md

TypeBuilder

一个用于生成泛型的简易Builder

Example for List<String>

Type type = TypeBuilder
        .newInstance(List.class)
        .addTypeParam(String.class)
        .build();

Example for List<? super String>

Type type = TypeBuilder
        .newInstance(List.class)
        .addTypeParamSuper(String.class)
        .build();

Example for List<? extends CharSequence>

Type type = TypeBuilder
        .newInstance(List.class)
        .addTypeParamExtends(CharSequence.class)
        .build();

Example for Map<String, String[]>

Type type = TypeBuilder
        .newInstance(HashMap.class)
        .addTypeParam(String.class)
        .addTypeParam(String[].class)
        .build();

Example for Map<String, List<String>>

Type type = TypeBuilder
        .newInstance(Map.class)
        .addTypeParam(String.class)
        .beginSubType(List.class) //开始 List<String> 部分
        .addTypeParam(String.class) //设置List的泛型值
        .endSubType() //结束 List<String> 部分
        .build();

Download

Get it from JitPack repository use Gradle or Maven.
Download JAR and Source

有什么用

当你无法通过子类去获取泛型时,不用写一长串的嵌套或去实现部分Type接口。

License

Copyright 2016 ikidou

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You can’t perform that action at this time.