File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Interface problems... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface problems..." Watch "Interface problems..." New topic
Author

Interface problems...

Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
I'm writing some code to handle user preferences. To do this, I wrote the following Node.java file:



Then, I created the following Registry.java file...




I'm really trying to use an interface correctly. However, on line 8, my IDE is giving me the following error: "Interface expected here". What's going on? As soon as I typed implements Node, the IDE offered to populate all of my method headers.

I'm confused.
[ April 15, 2005: Message edited by: Marcus Laubli ]

Marcus L´┐Żubli, SCJP 1.4, CLP 5.0, SCWCD 1.4 (preparing)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18108
    
  39

Node is an abstract class, not an interface.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
I admit, this is the part that I was weakest on in my exam!

So all I have to do is change it to:

public interface Node?
[ April 15, 2005: Message edited by: Marcus Laubli ]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
sure, why dont you try it?


java amateur
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
I tried, but Studio Creator still shows the error. It's confusing.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18108
    
  39

Originally posted by Marcus Laubli:
I admit, this is the part that I was weakest on in my exam!

So all I have to do is change it to:

public interface Node?


That depends on whether is it an interface or an abstract class.

If it is just interface definitions then sure. If it is an abstract class, then extending from it is probably easiest.

BTW, for either case, your IDE should complain and offer to generate stubs for all the methods -- at least the good ones, anyway.

Henry
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
Thanks for the help.

The error went away. I'm dealing with other things now. I think I can manage.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
of course you need to declare at least one method in your interface:

public SomeType myMethod1();
satyendra adhikari
Ranch Hand

Joined: Aug 17, 2001
Posts: 52
"of course you need to declare at least one method in your interface:"


not at all, you can have all empty interface, also called marker interface.
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
Thanks Guys!

It finally went up. It's taken so long, but this exercise made it click. Now I understand...

What I really want is:

public abstract class Registry implements Node

I'll put the rest of my abstract method definitions into here for the registry specific things, then create SystemNode.java and UserNode.java to finish the job.

Man, Java really is cool! "I love it when a plan comes together!"
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
thanks, satyendra

its quite well explained here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface problems...
 
Similar Threads
Append objects to List and show them.
Preferences API
Why Would new Date Cause an Exception
Preferences.exportSubTree() does not export all xml nodes
The method list(FilenameFilter) in the type File is not applicable for the arguments (FilenameFilter