我需要获得Class< ?扩展名单< AlarmRule> >实例
这是我的代码:
public static BoundedMatcher<Object, List<AlarmRule>> setBind() {
Class<? extends List<AlarmRule>> clazz = null; // I need to give clazz a value,but i don't know how.
return new BoundedMatcher<Object, List<AlarmRule>>(clazz) {
@Override
public void describeTo(Description description) {
description.appendText("with item content: ");
}
@Override
protected boolean matchesSafely(List<AlarmRule> list) {
return list.stream().anyMatch(alarmRule -> test_reminder_corn.equals(alarmRule.cron));
}
};
}
感谢您的帮助!
答案 0 :(得分:1)
在您的情况下,您需要在构造函数中传递List.class
。
但是,由于java类型擦除,任何List
都可以传递给匹配器,因此您需要添加其他代码以确保列表实际包含AlarmRule
个对象,否则您将得到{{1}在运行时。
答案 1 :(得分:1)
像这样写
public static BoundedMatcher<Object, List> setBind() {
return new BoundedMatcher<Object, List>(List.class) {
@Override
public void describeTo(Description description) {
description.appendText("with item content: ");
}
@Override
protected boolean matchesSafely(List list) {
// convert every object in list to AlarmRule
return false;
}
};
}