<< Thursday Sanity Check: What Do You Hear | Home | Mono 2.0 Is Released >>

Friday Java Quiz: Compile Or No Compile?

Q: Compile, or no compile?

public class Foo {
  public static void main(String[] args) {
    Integer Object = new Integer(1024);
    Object Integer = Object;
    System.out.println(Integer);
  }
}
Tags :


Re: Friday Java Quiz: Compile Or No Compile?

I think it will not compile, since 'Object' is a reserved word in Java.

Re: Friday Java Quiz: Compile Or No Compile?

It looks funny, but I don't think java has restrictions on upper case variable names that are keywords. I've run across a string variable before. I'm going with with it will compile with a 30% confidence factor ;)

Re: Friday Java Quiz: Compile Or No Compile?

I once saw some code like SubmissionXML SubmissionXML = new SubmissionXML(doc); It compiled.

Re: Friday Java Quiz: Compile Or No Compile?

hell lot of new information for me. I never thought or tried on it. But i am not sure about the justification being given. How come java miss such a basic "syntax" check. Is it really this reason or there is something else we are missing to explain this code?

Re: Friday Java Quiz: Compile Or No Compile?

Compile. Neither Integer or Object are reserved words in Java, so they are legal indentifiers. The only words that can't be used as identifiers are words that are reserved or which do not meet the rules for identifiers.

Add a comment Send a TrackBack