Using Guava ClassPath I am trying to initialize classes located in a specific package, but I want to use a constructor to initialize as this does not apply to exceptions. Here is what I developed to create constructors:
ClassPath.from(classLoader).getTopLevelClasses("test.package").stream() .map(ClassPath.ClassInfo::load) .map(Class::getConstructors) .map(Arrays::stream) .map(constructorStream -> constructorStream .filter(constructor -> constructor.getParameterCount() == 0) .findAny() .orElseThrow(RuntimeException::new) );
However, this leads to an error in InteliJ by simply declaring a cyclic interface. I think I know what the loopback interface is, but I'm not sure why this might cause this error. As far as I know, as long as the return type is known (for orElseThrow it has a return value in this case as Constructor<?> ), Then throwing an unchecked exception should be fine. If I use orElse(null) , the error will disappear. What happens here and how can I throw a RuntimeException that I want to throw?
java lambda guava java-8
danthonywalker
source share