title: Fixing error in java: incompatible types: java.lang.Object cannot be converted to capture#1 of?
body: <p>My code declares a value variable of type Object:</p>
  
  <p><code>final Object value;</code></p>
  
  <p>This variable is then loaded with an object.</p>
  
  <p>A generic collection variable is then declared and loaded:</p>
  
  <p><code>final Collection&lt;?&gt; c = (Collection&lt;?&gt;) argumentDefinition.getFieldValue();</code></p>
  
  <p>The collection variable is generic in both instances above, with brackets and a question mark that don't pass through in this text.</p>
  
  <p>When I try to use the add method of the collection:</p>
  
  <p><code>c.add(value)</code></p>
  
  <p>I get the error message:</p>
  
  <blockquote>
    <p>java: incompatible types:java.lang.Object cannot be converted to capture #1 of ?</p>
  </blockquote>
  
  <p>The add method is declared in Collection as:</p>
  
  <p><code>boolean add(E e);</code></p>
  
  <p>How can I fix the error? I think I understand what's going on - the compiler creates a placeholder for the generic type that Object isn't compatible with. I can't use a raw type for the collection because I'm trying to eliminate raw types in the code. Do I need to use a helper function, and if so how exactly? Thank you.</p>