aspose file tools*
The moose likes Beginning Java and the fly likes Why is the compiler generates an error message of this type? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why is the compiler generates an error message of this type?" Watch "Why is the compiler generates an error message of this type?" New topic
Author

Why is the compiler generates an error message of this type?

Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167


In the above code the instanceof operator is spelled incorrectly as instanceOf, by making the "O" of "of" capital.In this situation why is the compiler outputs an error message advising to include a parenthesis at the left hand side of obj1 and other error messages


Varuna Seneviratna
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Compiler error recovery is a very tricky topic. I think the only way you can really get a feel for the issues involved is by writing some compiler yourself. Basically, while it's easy to write a program that recognizes correct source code, it's exceedingly difficult to write one that recognizes the true intent of invalid source.


[Jess in Action][AskingGoodQuestions]
Sivakumar Janardhanan
Ranch Hand

Joined: Dec 11, 2008
Posts: 30
Hi Varuna, i think instanceOf is not a java keyword. that why the compiler gives an error message. now you use this java keyword "instanceof" instead of "instanceOf". it will execute properly.

ok bye
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10923
    
  12

my guess is that it thinks you are trying to cast a reference you are declaring. In other words, it thinks you are declaring a reference you name 'Parent' of the type 'instanceOf', and are trying to cast it to a reference of type 'obj1'.

(obj1) instanceOf Parent;


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19552
    
  16

Originally posted by sivakumar janardhanan:
Hi Varuna, i think instanceOf is not a java keyword. that why the compiler gives an error message. now you use this java keyword "instanceof" instead of "instanceOf". it will execute properly.

ok bye

I think we have a winner!


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36555
    
  16
The original poster knew about the O/o problem; he mentioned it in his first post. I thought the question was not "why do we get an error?" but "why does this error produce this message?"
Ken Liao
Greenhorn

Joined: Dec 15, 2008
Posts: 11
Originally posted by Rob Prime:

I think we have a winner!


I agree.^_^


A man takes responsibility for his actions, right or wrong - <<Battlestar Galactica>>
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36555
    
  16
"kendarkfire" please read the important administrative private message which I have just sent you.

CR
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why is the compiler generates an error message of this type?
 
Similar Threads
problem with compiler's no problem:-(
instanceof Operator
Error in Java
Downward casting
instanceof operator???