Its been years since I've used Java, this one is stumping me...

I implemented my own Observer/Observable interfaces for use with a 2-way RMI setup(I'm sure theres a better name but I don't know it yet).
I have 2 interfaces ToyStore and ToyFactory. ToyStore extends Remote implements Observer, ToyFactory extends Remote implements Observable. I then have a Server class that implements ToyFactory and a Client class that implements ToyStore(I won't post the code for these 2 yet, I don't think its the problem but if need be I can post).


This is what I get when I compile:

$ javac -d ./test Client.java Server.java Observable.java Observer.java ToyFactory.java ToyStore.java
ToyFactory.java:7: '{' expected
        extends Remote 
                      ^
ToyStore.java:7: '{' expected
        extends Remote 
                      ^
2 errors

Observer.java

package toys;

public interface Observer
{
    public void update(Observable o);
}

Observable.java

package toys;

public interface Observable
{
    public void addObserver(String s);
}

ToyStore.java

package toys;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface ToyStore 
    extends Remote 
    implements Observer
{
    String sayHi() throws RemoteException;
    public void update(Observable o) throws RemoteException;
}

ToyFactory.java

package toys;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface ToyFactory
    extends Remote 
    implements Observable
{
    String sayHello() throws RemoteException;
    public void addObserver(String s) throws RemoteException;
}

Am I compiling this wrong? Am I allowed to extend and implement in an interface? Does extending Remote block me from Implementing Observer/Observable? Missing semicolon? Let me know if I need to post the other 2 files...Thanks for the help.

Recommended Answers

All 3 Replies

An interface cannot implement anything, since an interface is not an implementation. An interface can only extend interfaces (exactly one).

Edit:

PS If you are a David Eddings fan, it is spelled Belgarath not Balgarath. If not, then please ignore.

Thanks a lot...I didn't really need the Observer/Observable files anyway I can just make ToyFactory and ToyStore require those methods.

David Eddings fan - yes, great books.

I spelled it that way on purpose, used that name in Ultima Online years ago and it kind of stuck.

David Eddings fan - yes, great books.

I spelled it that way on purpose, used that name in Ultima Online years ago and it kind of stuck.

Just wanted to check that that was what it looked like. ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.