I really researched a lot before asking about it, it seems like I'm missing something. I am trying to implement ServiceLoader and therefore made an example class:
the code is simple:
testInterface.java
package com.test;
public interface testInterface {
void test();
}
testImpl.java
package com.test;
public class testImpl implements testInterface {
@Override
public void test() {
System.out.println("test");
}
}
Main.java
package com.test;
import java.util.ServiceLoader;
public class Main {
public static void main(String[] args) {
ServiceLoader<testInterface> serviceLoader = ServiceLoader.load(testInterface.class);
serviceLoader.iterator().next().test();
}
}
com.test.testInterface
com.test.testImpl
I keep getting a NoSuchElementException on the iterator part, which means the implementation has not been loaded. Thanks in advance.
source
share