Note that there are some explanatory texts on larger screens.

plurals
  1. POFor loop with generic collection fails to compile in Java 7
    primarykey
    data
    text
    <p>Maybe someone can explain the behaviour below. I know there were some generic type-handling changes from Java 6 to 7, but I couldn't find one to explain this.</p> <p>This is happening with this library:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.apache.felix&lt;/groupId&gt; &lt;artifactId&gt;org.apache.felix.framework&lt;/artifactId&gt; &lt;version&gt;3.2.2&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>And the following demonstration code:</p> <pre><code>import org.apache.felix.framework.util.manifestparser.ManifestParser; ManifestParser manifestParser = new ManifestParser(null, null, null, null); for (Capability capability : manifestParser.getCapabilities()) { capability.toString(); } // where the signature of getCapabilities() is: // public List&lt;Capability&gt; getCapabilities() { return m_capabilities; } // and there are no other methods with similar signatures or names </code></pre> <p>This demo code compiles just fine with JDK 6 (x86, 1.6.0_45, 32-bit), but fails to compile with JDK 7 (x86, 1.7.0_25, 32-bit, same host):</p> <pre><code>// line number matches the for loop java: incompatible types required: org.apache.felix.framework.capabilityset.Capability found: java.lang.Object </code></pre> <p>After some head scratching, I have a workaround but no explanation. The following modification to the demo code compiles with JDK 7:</p> <pre><code>ManifestParser manifestParser = new ManifestParser(null, null, null, null); List&lt;Capability&gt; capabilities = manifestParser.getCapabilities(); for (Capability capability : capabilities) { capability.toString(); } </code></pre> <p>Why is this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload