Note that there are some explanatory texts on larger screens.

plurals
  1. POJava generics code compiles in eclipse but not in command line
    primarykey
    data
    text
    <p>I know there have been several questions in the past regarding things that compile in eclipse but not in command line, but I could not find an answer to my problem yet.</p> <p>In particular, I think that I was able to set eclipse to use my system compiler, but that still did not solve the problem.</p> <p>I am currently checking under : 'Preferences -> Java -> Installed JREs'. </p> <p>This contains only one JRE which is my system one.</p> <p><strong>Here are the specifics of the problem</strong></p> <p>I have a java generic class that takes as argument an Enum type, like so:</p> <pre><code>public class MyClass&lt;T extends Enum&lt;T&gt;&gt; </code></pre> <p>Somewhere inside the class I compare a known enum value with values of T. So for example let's assume I have this enum:</p> <pre><code>public enum OtherEnum{ a, b } </code></pre> <p>And then I test:</p> <pre><code>protected void foo(T enumVal){ if(enumVal == OtherEnum.a){ // do something } else if(enumVal == OtherEnum.b){ // do something else } } </code></pre> <p>This compiles with no problem in eclipse but in command line javac I get this error:</p> <blockquote> <p>incomparable types: T and OtherEnum</p> </blockquote> <p>I tried this on two systems that use variant of java 1.6 (1.6.0_26 and 1.6.0_16). One is a Mac, the other a linux. They both give the same error, while eclipse is compiling away with no problem.</p> <p>So:</p> <ol> <li><p>How do I make sure which compiler eclipse is using?</p></li> <li><p>What is even the problem here?</p></li> </ol> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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