さまざまな列挙型でスーパータイプを使用できるようにしたいのですが、コードは次の 3 つの部分で構成されています。
Manager.search:
public final List<B> search(final Order order, final Field field, final AbstractConstraint... c) throws SearchException {
if (c.length == 0) {
throw new IllegalArgumentException("orm.Manager.search: c.length == 0");
}
try {
List<B> beans = new ArrayList<>();
for (AbstractConstraint constraint : c) {
try (PreparedStatement ps = new QueryBuilder(connection, tableName(), getPaths(), searchQuery()).add(constraint).order(order, field).build();ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
beans.add(createBean(rs));
}
}
}
return beans;
} catch (SQLException ex) {
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex);
throw new SearchException(ex);
}
}
ここでは変数order
とfield
変数が最も重要です。
自動生成された TemplateAttributeField.java:
public enum TemplateAttributeField implements Field {
templateId,
attributeOrder,
attributeName,
x1,
x2;
}
そして呼び出しコード:
try (TemplateAttributeManager templateAttributeManager = ManagerFactory.getTemplateAttributeManager()) {
List<TemplateAttributeBean> templateAttributes = null;
try {
templateAttributes = templateAttributeManager.search(Order.ASCENDING, TemplateAttributeField.attributeOrder, new TemplateAttributeConstraint.Builder().templateId(template.getTemplateId()).build());
} catch (SearchException ex) {
Logger.getLogger(OutputProcessor.class.getName()).log(Level.SEVERE, null, ex);
}
for (Word word : words) {
}
}
ただしtemplateAttributes = ...
、次の例外/エラーが発生します。
no suitable method found for search(Order,TemplateAttributeField,TemplateAttributeConstraint)
method Manager.search(Order,Field,AbstractConstraint...) is not applicable
(actual argument TemplateAttributeField cannot be converted to Field by method invocation conversion)
また、Field
クラスは、追加の機能を妨げないインターフェース以上のものです。
ここに何かが欠けていますか、それともどうすれば修正できますか?