我有一个这样读取的服务接口
package services;
import domain.Items;
public interface IItemsService extends IService {
public final String NAME = "IItemsService";
/** Places items into the database */
public void storeItem(Items items);
/** Retrieves items from the database
*
* @param category
* @param amount
* @param color
* @param type
* @return
* @throws ClassNotFoundException
*/
public Items getItems (String category, float amount, String color, String type) throws ItemNotFoundException, ClassNotFoundException;
}
还有一个看起来像这样的工厂...
package services;
public class Factory {
public Factory(){}
@SuppressWarnings("unchecked")
public IService getService(String name) throws ServiceLoadException {
try {
Class c = Class.forName(getImplName(serviceName));
return (IService)c.newInstance();
} catch (Exception e) {
throw new ServiceLoadException(serviceName + "not loaded");
}
}
private String getImplName (String name) throws Exception {
java.util.Properties props = new java.util.Properties();
java.io.FileInputStream fis = new java.io.FileInputStream("properties.txt");
props.load(fis);
fis.close();
return props.getProperty(serviceName);
}
}
这应该很简单 - 但我不断收到两个错误 - IService 无法解析为类型(在工厂和服务上),并且 serviceName 也无法解析为工厂中的变量错误。我知道我错过了一些简单的东西......