我想通过反射访问方法。问题是该方法在接口中注释:
\n\npublic interface MyRepository extends CrudRepository<MyClass, Long> {\n\n @CustomAnnotation\n MyClass findByName(String name);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n正如您所看到的,我使用 Spring,它提供了一个将实现此 Repository 接口的类。\n我想创建一个方法,它将获取一个 Repository 并调用所有用@CustomAnnotation.
public void do(Repository<?, ?> repository){\n Method[] methods=repository.getClass().getMethodThatAreAnnotatedInInterfaceWith(CustomAnnotation.class);\n ....\n}\nRun Code Online (Sandbox Code Playgroud)\n\n因为接口的实现不会有接口的注释,所以我不知道如何查询这些方法。
\n我有一个问题,我想知道是否有使用 Streams 的解决方案。
想象一下你有一个有序的对象流;让我们假设一个整数流。
Stream<Integer> stream = Stream.of(2,20,18,17,4,11,13,6,3,19,4,10,13....)
Run Code Online (Sandbox Code Playgroud)
现在我想过滤一个值与该值之前的前一个数字之差大于n的所有值。
stream.filter(magicalVoodoo(5))
// 2, 20, 4, 11, 3, 19, 4, 10 ...
Run Code Online (Sandbox Code Playgroud)
我有可能这样做吗?