-
Notifications
You must be signed in to change notification settings - Fork 13k
optimize TypeParameterResolver #3512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Hello @guanchengang ,
You will get class C extends B<Integer> {} [1] There should be a compiler warning: The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended |
I'm sorry I gave an inappropriate example @harawata. class L0 {}
class L1 extends L0 {}
class A<AT extends L0> {
public AT foo() {
return null;
}
}
class B0 extends A {
}
class B1<BT1 extends L0> extends A<BT1> {
}
class B2<BT2 extends L1> extends A<BT2> {
}
public static void main(String[] args) throws Exception {
Method foo = A.class.getMethod("foo");
System.out.println(TypeParameterResolver.resolveReturnType(foo, A.class)); // class com.example.Test$L0
System.out.println(TypeParameterResolver.resolveReturnType(foo, B0.class)); // class com.example.Test$L0
System.out.println(TypeParameterResolver.resolveReturnType(foo, B1.class)); // class java.lang.Object
System.out.println(TypeParameterResolver.resolveReturnType(foo, B2.class)); // class java.lang.Object
} Subclass loses more information after extending from A. |
Assuming you need this enhancement for some mappings in your MyBatis application (let me know if this is not the case), please create a small demo project that demonstrates the actual usage (including DB data, mapper, Java classes, etc.) and share it on your GitHub repo. Here are some project templates and examples. I couldn't think of a good example that benefit from this in the context of MyBatis mappings. |
@harawata , |
Thank you , @guanchengang ! I will look into it, but it might take a while as it's not an urgent matter. |
Mixing |
There may be some issues when comparing |
Hi @guanchengang , I'm sorry about the slow response. The change to the
If two And I can see that it could return I also understand that there could be other issues caused by the implementation differences, however, users can get And let's skip the "more precise boundary" part as well. To summarize:
[1] I found an open ticket discussing |
17f0bb2
to
a863e58
Compare
hello @harawata, Additionally, there is another issue in equals() . class A {
public List<String>[] foo() {
return null;
}
}
TypeParameterResolver.GenericArrayTypeImpl mybatisGA =
new TypeParameterResolver.GenericArrayTypeImpl(new TypeParameterResolver.ParameterizedTypeImpl(List.class, null, new Type[]{String.class}));
Method foo = A.class.getMethod("foo");
Type jdkGA = A.class.getMethod("foo").getGenericReturnType();
System.out.println(jdkGA.equals(mybatisGA)); // true
System.out.println(mybatisGA.equals(jdkGA)); // false a.equals(b) and b.equals(a) have different results. |
|
||
assertTrue(typeJdk instanceof ParameterizedType && !(typeJdk instanceof TypeParameterResolver.ParameterizedTypeImpl)); | ||
assertTrue(typeMybatis instanceof TypeParameterResolver.ParameterizedTypeImpl); | ||
assertEquals(typeMybatis.equals(typeJdk), typeJdk.equals(typeMybatis)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick question:
This assertion passes when 1) both "expected" and "actual" are true
OR 2) both "expected" and "actual" are false
.
I understand 1), but why is 2) valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the result of a.equals(b)
and b.equals(a)
should be symmetric, meaning that if one evaluates to true, so should the other. Therefore, a not equals b
and b not equals a
can logically be considered valid.
Comparing the following two forms:
assertEquals(typeMybatis.equals(typeJdk), typeJdk.equals(typeMybatis));
and
assertTrue(typeMybatis.equals(typeJdk));
assertTrue(typeJdk.equals(typeMybatis));
Personally, I prefer the first option, as it not only emphasizes the symmetry of the object comparison but also avoids the redundancy of repeated assertions.
optimize TypeParameterResolver