casting - java unchecked cast required: Class<A> found: Class<CAP#1> where CAP#1 is a fresh type-variable -
i trying rid of compiler warnings in code, , 1 little frustrating.
i need functional operations class
object of particular class i've created. let's illustrate code:
public static void main(string[] args) { obj = getobj(); class<a> clazz = obj.getclass(); } static class {} static getobj() { return new a(); }
this code throws compiler error:
incompatible types: class<cap#1> cannot converted class<a> cap#1 fresh type-variable: cap#1 extends capture of ? extends
ok, cast obj
getclass()
:
class<a> clazz = (class<a>)obj.getclass();
and warning (better error):
[unchecked] unchecked cast required: class<a> found: class<cap#1> cap#1 fresh type-variable: cap#1 extends capture of ? extends
so, how check class cast?
tried this:
class c = obj.getclass(); class<a> clazz = c instanceof class<a> ? (class<a>)c : null;
but produced warning , error.
so i'm stumped.
Comments
Post a Comment