我正在使用提供程序创建Predicate实例。
@Provides
@Singleton
@Named("RecordFilters")
public Predicate<ImmutablePair<AbstractRecord, StreamRecord>> getAllFilters() {
BackfillDataFilter backfillDataFilter = new BackfillDataFilter();
DummyUpdateFilter dummyUpdateFilter = new DummyUpdateFilter();
return input -> dummyUpdateFilter.test(input) && backfillDataFilter.test(input);
}
当我尝试使用injector.getInstance(Predicate.class)
或injector.getInstance(Key.get(Predicate.class, Names.Named("RecordFilters"))
我得到了例外。
com.google.inject.ConfigurationException: Guice configuration errors:
No implementation for java.util.function.Predicate was bound.
while locating java.util.function.Predicate
请建议。
答案 0 :(得分:2)
按照answer:
中的说明进行尝试injector.getInstance(Key.get(new TypeLiteral<Predicate<ImmutablePair<AbstractRecord, StreamRecord>>>(){})