, , . Foo - , LHS . Java... .
, , , :
Class fooClass;
if (loadFoo1) {
fooClass = Class.forName("some.pkg.Foo1");
} else {
fooClass = Class.forName("some.pkg.Foo2");
}
Foo foo = (Foo) fooClass.newInstance();
( ...)
, fooClass Class, , . . , "" ... .
HOWEVER... , . , , , , , factory; . @andersoj.
UPDATE
, , , . (.. Foo1.method() Foo2.method()) , .
, , , Java:
- , ; .
Class fooClass;
// Load one or other of the classes as above.
Method m = fooClass.getDeclaredMethod("method");
Integer res = (Integer) m.invoke(null);
( , )
, . , :
public static int method() {
return useFoo1 ? Foo1.method() : Foo2.method();
}
OO: method Foo , Foo1 Foo2 .
, , method()... Foo1.method Foo2.method .