Hello everyone, I am having a small problem with co-variance. I am using two different Java libraries and one returns a Class<in T> (Class<? super T>) and the other expects a Class<T> as an argument.
I am getting a type mismatch "Required: Class<T> Found: Class<in T!>!".
I am sure there is a simple solution 🙂 but I can't figure out how to get from the one to the other.
Any tips?
m
Marc Knaup
01/29/2019, 10:52 PM
Well you can just cast it
as Class<T>
But the question is why the libraries return and expect it in the way they do and whether passing one to the other makes sense.
j
Jeff Thomas
01/29/2019, 11:24 PM
Thanks Marc, that is what I was going with but was getting unchecked cast warning and wanted to be sure that the cast was ok... still grappling with the co-variant concepts... 😐
Well the first library is google gson... it returns the raw type of a TypeToken as Class<? super T>. I am trying to use that to create a generic class which takes a Class<T> argument.