public class A<T> {
public <K> void m(A<K> target) {
// determine if T equals K
}
}
Is it possible to check if <T> and <K> are the same types?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, this works the same way as the generic TypeReference. Normally types are erased but it works with anonymous inner classes:
To use it:
The class does not have to be abstract but it serves as a reminder to make it anonymous inner class. The only real downside is that you have to put
{}in the end.