• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Interface problems...

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sure, why dont you try it?
 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried, but Studio Creator still shows the error. It's confusing.
 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
of course you need to declare at least one method in your interface:

public SomeType myMethod1();
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, satyendra

its quite well explained here
reply
    Bookmark Topic Watch Topic
  • New Topic