-1

I have literally just started and I think this is such a basic question that I can't even find anything online about it but I can't for the life of me figure this out.

I have two seperate bundles, one an API and one a Service bundle. In a package in the API bundle I have an interface called "HelloAPI":

package com.example.osgi.api;

public interface HelloAPI {

    public void sayHello();

}

In the service bundle I have a class with the following code:

package com.example.osgi.service;

public class HelloImpl {

    implements HelloAPI {
        System.out.println("Hello World!");
    }
}

but eclipse has highlighted an error under the "implements" keyword which is:

Syntax error on token "implements", interface expected.

I can't see what I've done wrong, can anyone point me in the right direction? Thanks.

Jake B
  • 27
  • 7
  • `implements` goes right after the class name. You have a `{` in between. Also your methods definiton is wrong. You may want to wait with OSGi until you have your basic understanding of the language in place. Especially classpaths. – Thorbjørn Ravn Andersen Feb 15 '17 at 10:00
  • @ThorbjørnRavnAndersen I'm being thrown in the deep end here, playing catch-up is all I'm ever doing. What's wrong with my method definition? – Jake B Feb 15 '17 at 10:24
  • https://docs.oracle.com/javase/tutorial/java/IandI/usinginterface.html – Balazs Zsoldos Feb 15 '17 at 11:45
  • 2
    Your question is very basic and indicates very little experience with writing Java programs. If you are expected to do this in an OSGi setting, you are in for a very, very steep learning curve. If those who threw you in the deep end are unaware of that, this could become a very unpleasant experience. I would suggest bringing your problems to their attention so you have time to learn the Java basics first. – Thorbjørn Ravn Andersen Feb 15 '17 at 13:59
  • 3
    You should learn java before OSGi... – Alexandre Cartapanis Feb 15 '17 at 14:18

1 Answers1

2

I strongly agree with the comments — it's vital to learn the fundamentals of the Java language before tackling more advanced topics like modularity.

For reference, here is a correct implementation of your interface:

public class HelloImpl implements HelloAPI {
    public void sayHello() {
        System.out.println("Hello World!");
    }
}
Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77