I am trying to write something like a frame. I need to find a specific folder on my computer and be able to get all the class files that exist that implement my interface. Although I know how to scan a folder and check all class files, somehow I canβt check if the reading class implements my interface.
if (Game.class.isAssignableFrom(classInFolder)) { //Do sth here }
The approach I tried but it never jumps in if clause - Game is my Interface
public interface Game { public void startAlgorithm(); }
and classInFolder is the class I got from my folder. It's funny if I try to do the same with some library interface - let them say that Serializable works fine - I tried. What else when I wrote something like this
Type[] type = classInFolder.getGenericInterfaces(); for (int i = 0;i<type.length;++i) { System.out.println("interface = " + type[i]); if (type[i] instanceof Game){ System.out.println("It is"); } }
I got my console output - interface = mypackage.Game But there wasnβt "This." The same thing happened with my own annotation in the class that I tried to use - I canβt check if my class implements my interfaces, but it works when these are interfaces from some library. I am deploying my project on tomcat v 7.0, everything works on Java 7 on Eclipse using Spring.
I would be grateful for any ideas on what might happen.
source share