guice例子
所属分类 guice
浏览量 707
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.inject.Guice;
import com.google.inject.Injector;
@Singleton
public class HelloDemo {
@Inject
private HelloPrinter printer;
public void hello() {
printer.print();
}
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector();
HelloDemo helloDemo = injector.getInstance(HelloDemo.class);
helloDemo.hello();
}
}
@Singleton
class HelloPrinter {
public void print() {
System.out.println("Hello, guice");
}
}
https://gitee.com/dyyx/hellocode/blob/master/demo/guicedemo/src/main/java/dyyx/hellodemo/HelloDemo.java
上一篇
下一篇
GO gc 要点
git的几个实用命令
networking io with virtual threads
java 虚拟线程使用
project loom 那些事
JDK18 特性