Skip to content

Can I make the code shorter ? #572

Answered by lukehutch
eitan-rosenberg asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by eitan-rosenberg
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants