File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 1 error when compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "1 error when compiling" Watch "1 error when compiling" New topic

1 error when compiling

Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
Hi all, I got this error - "cannot resolve symbol ... myInterfaceReference.sayHelloFromMyClass()". Any comments would be great!

[ July 19, 2006: Message edited by: Shanel Jacob ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
It is true that the return type of the method getMyClass() is MyInterface, and MyClass implements MyInterface.

However, the method sayHelloFromMyClass() is not a member of MyInterface, so unless you cast myInterfaceReference to a MyClass reference, or add the method header of sayHelloFromMyClass() to MyInterface, you can't call sayHelloFromMyClass() with myInterfaceReference.
[ July 19, 2006: Message edited by: Keith Lynn ]
Daniel Bryant
Ranch Hand

Joined: Jul 15, 2006
Posts: 54
I totally agree with Keith. I think what you mean to code was

or if you wanted to explore the casting Keith mentioned you could alter your main method to:


SCJP 1.4,<br />SCJD (URLyBird 1.2.1, JDK 5.0)
Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
Hi Keith and Daniel, I tried both suggested fix and managed to compile without errors. Thank you very much (again!)
I agree. Here's the link:
subject: 1 error when compiling
It's not a secret anymore!