【发布时间】:2011-08-19 05:54:49
【问题描述】:
Java 中的运行时依赖项是如何工作的。例如,如果 Impl1 或 Impl2 在运行时不在类路径中,这样的代码是否可行:
Thinger t;
if (classIsAvailable(Impl1.class)) t = new Impl1();
else t = new Impl2();
t.doThing();
或者如果没有通用接口:
if (classIsAvailable(Impl1.class)) Impl1.doThingThisWay();
else Impl2.doThingTheOtherWay();
【问题讨论】:
标签: java dependencies runtime classpath