Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Generics Error: The method is not applicable for the arguments
    primarykey
    data
    text
    <p>I'm developing an Android application and I'm using generics for a part of it. However I'm getting a compiler error that I'm unable to understand.</p> <p>I have the following architecture:</p> <pre><code>public interface IMakeableEncryptionBundle&lt;T, F&gt; { public void setConfigurationFactory(F configurationFactory); } public class VigEncryptionBundle implements IMakeableEncryptionBundle&lt;ITextContent, VigConfigurationFactory&gt; { @Override public void setConfigurationFactory(VigConfigurationFactory configFactory) { // Set the factory. } } public interface IConfigurationFactory { } public final class VigConfigurationFactory implements IConfigurationFactory { } </code></pre> <p>And I use it like this:</p> <pre><code>private IMakeableEncryptionBundle&lt; ITextContent, ? extends IConfigurationFactory&gt; encryptionBundle = new VigEncryptionBundle(); </code></pre> <p>And this is what causes the error:</p> <pre><code>VigConfigurationFactory configFactory = (VigConfigurationFactory) configObj; encryptionBundle.setConfigurationFactory(configFactory); </code></pre> <p><strong>"The method setConfigurationFactory(capture#8-of ? extends IConfigurationFactory) in the type IMakeableEncryptionBundle is not applicable for the arguments (VigConfigurationFactory)"</strong></p> <p>But isn't this exactly what "extends" is supposed to do? To allow you to use a subclass/implementation in place?</p> <p>Also neither this is working:</p> <pre><code>encryptionBundle.setConfigurationFactory((IConfigurationFactory) configFactory); </code></pre> <p><br><br> <strong>Edit:</strong> What I'm trying to achieve, is have an independency of the particular <code>IConfiguration</code> implementation and put the instantiation of <code>encryptionBundle</code> in an external class.</p> <p>At the same time I need generics to make sure a particular <code>IMakeableEncryptionBundle</code> implementation can use it's own <code>IConfiguration</code> implementation.</p> <p>In addition, the following as suggested below gives me another error:</p> <pre><code>private IMakeableEncryptionBundle&lt; ITextContent, IConfigurationFactory&gt; encryptionBundle = new VigEncryptionBundle(); </code></pre> <p><strong>"Type mismatch: cannot convert from VigEncryptionBundle to IMakeableEncryptionBundle"</strong></p> <p><br> I even tried to declare the following with no change:</p> <pre><code>public interface IMakeableEncryptionBundle&lt;T, F extends IConfigurationFactory&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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