return Class.forName(name).newInstance(); 事先不须要知道类是否存在。 X Factory.create(name)中return (X)context.lookup(name); 事先要绑定要Lookup的类,即使存在而没有绑定的类是LOOKUP不了的。--------------- [email protected]
how do you call the create() method anyway? if you say Factory.create("A"), what prevents you from saying new A()? if you read the class name from file, then there's no way around. you'll have to call newInstance() for at least once.
事先不须要知道类是否存在。
X Factory.create(name)中return (X)context.lookup(name);
事先要绑定要Lookup的类,即使存在而没有绑定的类是LOOKUP不了的。---------------
[email protected]
if you say Factory.create("A"), what prevents you from saying new A()?
if you read the class name from file, then there's no way around. you'll have to call newInstance() for at least once.