Note that there are some explanatory texts on larger screens.

plurals
  1. POType of a wildcard object without using "instanceof"
    text
    copied!<p>In the code below, I don't want to use <code>instanceof</code> to know the type of repository. Is it the only way to get the type? Is it possible to know de type with the wildcard <code>RepositoryVet&lt;?&gt;</code>? This would save me doing lots of test.</p> <pre><code>public ArrayList&lt;String&gt; rechercherTabTailles(String sexe,String SI,RepositoryVet&lt;?&gt; repository) { ArrayList&lt;String&gt; tabTailles; repository.Open(); repository.rechercherspin(sexe); if (SI.compareTo("US") == 0) { if (repository instanceof ChaussureRepository) tabTailles= ((ChaussureRepository) repository).taillesUS; if (repository instanceof ChemiseRepository) tabTailles= ((ChemiseRepository) repository).taillesUS; } } </code></pre> <p>To complete my question : RepositoryVet is already an abstractClass defined like this :</p> <p>public abstract class RepositoryVet implements IRepositoryVet {</p> <pre><code>public ArrayList&lt;String&gt; taillesEU; public ArrayList&lt;String&gt; taillesUS; public ArrayList&lt;String&gt; taillesUK; public ArrayList&lt;String&gt; taillesIT; public ArrayList&lt;String&gt; taillesJP; public ArrayList&lt;String&gt; taillescm; public ArrayList&lt;String&gt; taillesinch; </code></pre> <p>etc.... }</p> <p>And "ChaussureRepository" is a class that extends RepositoryVet like this :</p> <p>public class ChaussureRepository extends RepositoryVet {</p> <pre><code>public ArrayList&lt;String&gt; taillesEU; public ArrayList&lt;String&gt; taillesUS; public ArrayList&lt;String&gt; taillesUK; public ArrayList&lt;String&gt; taillesIT; public ArrayList&lt;String&gt; taillesJP; public ArrayList&lt;String&gt; taillescm; public ArrayList&lt;String&gt; taillesinch; </code></pre> <p>etc....</p>
 

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