pom.xml
org.reflections reflections0.9.10
IInit.java
package org.example.testsingleton;
public interface IInit {
void init();
}
Main.java
package org.example.testsingleton;
import org.reflections.Reflections;
import java.util.Set;
public class Main implements IInit {
public static int MIN_NAME_LEN = 0;
@Override
public void init() {
MIN_NAME_LEN = 1;
}
public static void login(String userName) {
if (userName.length() < MIN_NAME_LEN) {
System.out.println("名字过短");
} else {
System.out.println("ok");
}
}
public static void main(String[] args) {
Reflections reflections = new Reflections("org.example.testsingleton");
Set> set = reflections.getSubTypesOf(IInit.class);
set.forEach(c -> {
try {
IInit inst = c.getConstructor().newInstance();
inst.init();
} catch (Exception e) {
e.printStackTrace();
}
});
System.out.println(Main.MIN_NAME_LEN);
Main.login("11");
}
}



