Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange and different behaviour across netbeans, eclipse and compiler
    text
    copied!<p>I have this code in a single file : </p> <pre><code>public class genIntro { public static void main(String [] args){ genTest g = new genTest(); g.add( 10 ); System.out.println( g.get() == new Integer(10) ? true:false ); Integer in = (Integer) g.get(); } } class genTest(){ private Object object; public void add(Object object) { this.object = object; } public Object get() { return object; } } </code></pre> <p>The second class <code>genTest</code> has a wrong declaration seen with the brackets <code>()</code>.</p> <p>In Netbeans 6.9.1 the code runs correctly and outputs <code>false</code>.</p> <pre><code>Product Version: NetBeans IDE 6.9.1 (Build 201007282301) Java: 1.6.0_21; Java HotSpot(TM) 64-Bit Server VM 17.0-b17 System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb) Userdir: C:\Users\Name\.netbeans\6.9 </code></pre> <hr> <p>In Eclipse Indigo the code outputs :</p> <pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problem: at genIntro.main(genIntro.java:4) Version: Indigo Service Release 1 Build id: 20110916-0149 </code></pre> <hr> <p>Then manually compiling via the <code>javac</code> command I get :</p> <pre><code> genIntro.java:12: '{' expected class genTest(){ ^ 1 error </code></pre> <p>This is rather strange, can someone explain why the difference between them? Since it's erroneous why does it compile and run in Netbeans?</p> <p>Running via <code>javac genIntro.java</code></p> <p>They all use jre6</p> <p><em>Screenshot :</em> </p> <p><img src="https://i.stack.imgur.com/uIWO6.png" alt="enter image description here"></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