一个用于生成泛型的简易Builder
Type type = TypeBuilder
.newInstance(List.class)
.addTypeParam(String.class)
.build();
Type type = TypeBuilder
.newInstance(List.class)
.addTypeParamSuper(String.class)
.build();
Type type = TypeBuilder
.newInstance(List.class)
.addTypeParamExtends(CharSequence.class)
.build();
Type type = TypeBuilder
.newInstance(HashMap.class)
.addTypeParam(String.class)
.addTypeParam(String[].class)
.build();
Type type = TypeBuilder
.newInstance(Map.class)
.addTypeParam(String.class)
.beginSubType(List.class) //开始 List<String> 部分
.addTypeParam(String.class) //设置List的泛型值
.endSubType() //结束 List<String> 部分
.build();
Get it from JitPack repository use Gradle or Maven.
Download JAR and
Source
当你无法通过子类去获取泛型时,不用写一长串的嵌套或去实现部分Type接口。
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.