generics - Fixing error in java: incompatible types: java.lang.Object cannot be converted to capture#1 of? -
my code declares value variable of type object:
final object value;
this variable loaded object.
a generic collection variable declared , loaded:
final collection<?> c = (collection<?>) argumentdefinition.getfieldvalue();
the collection variable generic in both instances above, brackets , question mark don't pass through in text.
when try use add method of collection:
c.add(value)
i error message:
java: incompatible types:java.lang.object cannot converted capture #1 of ?
the add method declared in collection as:
boolean add(e e);
how can fix error? think understand what's going on - compiler creates placeholder generic type object isn't compatible with. can't use raw type collection because i'm trying eliminate raw types in code. need use helper function, , if how exactly? thank you.
it's hard tell problem without knowing argumentdefinition.getfieldvalue()
returns, possible solution change variable type collection<?>
collection<object>
.
Comments
Post a Comment