查看完整版本 : Error are Showing in Java Program

ankitdixit 2022-3-31 20:12

Hello All, I am working on java project and facing an error in below code. The code below won't compile, why?[code]System.out.println(Void.class instanceof Class);[/code]This won't compile either[code]//according to oracle doc, the type of Void.TYPE is ClassSystem.out.println(Void.TYPE instanceof Class);[/code]Errors are showing:[code]VoidTest.java:6: inconvertible types found : java.lang.Classrequired: Class System.out.println(Void.TYPE instanceof Class); [/code]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
I am using online compiler to compiler the program from here: [url=https://www.interviewbit.com/online-java-compiler/]https://www.interviewbit.com/online-java-compiler/[/url]

bickey 2022-9-9 07:31

嘗試咁樣,睇吓明唔明點用?

public class Program {
    public static void main(String args[]) {
      Void v = new Void();
      
      if (v instanceof Void) {
          System.out.println("instance of Void");
      }
      
      if (v instanceof Object) {
          System.out.println("instance of Object");
      }
      
      System.out.println( v instanceof Void ? "instanceof Void" : "not instanceof Void");
    }
}

class Void {   
}

[[i] 本帖最後由 bickey 於 2022-9-9 07:32 編輯 [/i]]
頁: [1]
查看完整版本: Error are Showing in Java Program