Correct approach to compare `ResolvedType` with a raw `Class<?>`?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
Hướng nghiên cứu
Bắt đầu với các API ResolvedType và TypeResolver được nêu trong issue, đặc biệt là resolve, getTypeParameters, getErasedType và equals. Tái hiện ví dụ GenericType và so sánh các cách tiếp cận raw-Class và resolved-type; kết quả cần đưa ra khuyến nghị rõ ràng về cách kiểm tra xem resolved type có phải là String hay không, bao gồm mọi overhead có liên quan.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 266
- Fork
- 47
- Merge trung bình
- 1 giờ 42 phút
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FasterXML/java-classmate
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FasterXML/java-classmate#111 · 10 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
FasterXML/java-classmate#81 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FasterXML/java-classmate#76 · 6 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FasterXML/java-classmate#69 · 22 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FasterXML/java-classmate#57 · 1 bình luận ·
Tất cả issue của FasterXML/java-classmate
Issue tương tự
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
apache/flink-agents#1152 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
jenkinsci/blueocean-plugin#5417 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
objectionary/eo-graphs#75 ·