Correct approach to compare `ResolvedType` with a raw `Class<?>`?
还没有人认领这个 Issue。
评估
调研方向
从 issue 中提到的 ResolvedType 和 TypeResolver API 开始,尤其是 resolve、getTypeParameters、getErasedType 和 equals。复现 GenericType 示例,并比较 raw-Class 和 resolved-type 两种方法;完成后应明确建议如何检查 resolved type 是否为 String,包括任何相关的 overhead。
由索引模型根据 Issue 内容生成。
描述
What's the appropriate way to see if a ResolvedType represents a simple class that I know about?
Let's say I pass a new GenericType<String>{} to a method, and I just want to see if the generic parameter is String. I think (I haven't tried it yet) I would do this (code not optimized, for illustration):
void foo(GenericType<?> genericType) {
TypeResolver typeResolver = new TypeResolver();
ResolvedType resolvedType = typeResolver.resolve(genericType);
How would I then see if resolvedType indicates a simple String? I'm guessing I could do this:
if(resolvedType.getTypeParameters.isEmpty() && resolvedType.getErasedType().equals(String.class)) {
…
But that seems sort of awkward. Is there a better way?
(Note that the resolvedType.getTypeParameters.isEmpty() check is arguably not necessary here, as String has no generic parameters, but I'm looking for a general approach.)
Or should I be going in the other direction, resolving String.class and then comparing the resolved types?
if(resolvedType.equals(typeResolver.resolve(String.class))) {
…
I don't know how much overhead the extra resolution of String.class adds, though.
This may be related to #31.
- 主要语言
- Java
- 星标
- 266
- 派生
- 47
- 平均合并
- 1 小时 42 分钟
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
FasterXML/java-classmate 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
FasterXML/java-classmate#111 · 10 条评论 ·
-
难度 5/5 一周以上 新手友好度 20/100
FasterXML/java-classmate#81 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
FasterXML/java-classmate#76 · 6 条评论 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 35/100
FasterXML/java-classmate#69 · 22 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
FasterXML/java-classmate#57 · 1 条评论 ·
查看 FasterXML/java-classmate 的全部 Issue
相似的 Issue
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
apache/flink-agents#1152 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 70/100
jenkinsci/blueocean-plugin#5417 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
objectionary/eo-graphs#75 ·