• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface problems...

 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Henry Wong
author
Marshal
Pie
Posts: 21427
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Node is an abstract class, not an interface.

Henry
 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure, why dont you try it?
 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried, but Studio Creator still shows the error. It's confusing.
 
Henry Wong
author
Marshal
Pie
Posts: 21427
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help.

The error went away. I'm dealing with other things now. I think I can manage.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
of course you need to declare at least one method in your interface:

public SomeType myMethod1();
 
satyendra adhikari
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, satyendra

its quite well explained here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic