The code below won't compile, why?
System.out.println(Void.class instanceof Class);
This won't compile either
//according to oracle doc, the type of Void.TYPE is Class<Void>
System.out.println(Void.TYPE instanceof Class);
The error message is
VoidTest.java:6: inconvertible types found : java.lang.Class<java.lang.Void> required: Class System.out.println(Void.TYPE instanceof Class);
And i am using Darwin Kernel Version 12.4.0 and Java version "1.6.0_51"
They won't compile using emacs + java + javac
They compile fine using online repl:http://www.javarepl.com/console.html or use eclipse on my machine
Promoting a comment to an answer...
I was able to duplicate the compiler error until I noticed I had a Class.class file in my directory (probably from attempting to analyze a past StackOverflow question).
I deleted that file, and then it compiled and ran just fine.
$ javac Main.java
Main.java:7: inconvertible types
found : java.lang.Class<java.lang.Void>
required: Class
System.out.println(Void.class instanceof Class);
^
Main.java:8: inconvertible types
found : java.lang.Class<java.lang.Void>
required: Class
System.out.println(Void.TYPE instanceof Class);
^
2 errors
$ rm Class.class
$ javac Main.java
$ java Main
true
true
Some custom Class class had taken precedence over the built-in java.lang.Class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With