Can I make the code shorter ? #572
-
I have this piece of code:
It is working just fine, can I make the code shorter ? Thanks for any response... Regards. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Yes, it is totally fine to chain these calls -- the API is designed to do this sort of thing. try (final ScanResult scanResult = new ClassGraph().acceptClasses(name).scan()) {
final File file = scanResult.getClassInfo(name).getResource().getClasspathElementFile();
System.out.println(file);
} The only thing you can't really avoid is using the try-with-resources pattern, since there may be resources that need to be closed. |
Beta Was this translation helpful? Give feedback.
-
If you're asking if there's a shorter way to get the classpath element that a certain class is contained within, no, there is no way currently to get that. I could probably provide a |
Beta Was this translation helpful? Give feedback.
Yes, it is totally fine to chain these calls -- the API is designed to do this sort of thing.
The only thing you can't really avoid is using the try-with-resources pattern, since there may be resources that need to be closed.