Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[additional] ServiceLoader #3

Open
wooyounggggg opened this issue Jul 4, 2022 · 0 comments
Open

[additional] ServiceLoader #3

wooyounggggg opened this issue Jul 4, 2022 · 0 comments
Assignees

Comments

@wooyounggggg
Copy link
Contributor

wooyounggggg commented Jul 4, 2022

연관 챕터

#1

조사 내용

책 내용 중 ServiceLoader라는 개념이 등장합니다. 관련하여, ServiceLoader가 어떻게 동작하는지 찾아보았습니다.

ServiceLoader는 대략 아래와 같은 형태로 사용할 수 있습니다.

/* SomeService.java */
public interface SomeService {
    doSomething();
}
...
public static void main(String[] args) {
    ServiceLoader<SomeService> loader = ServiceLoader.load(SomeService.class);
    Optional<SomeService> someServiceOptional = loader.findFirst();
    someServiceOptional.ifPresent(s -> {
        s.doSomething();
    });
}

위의 코드에서, ServiceLoader는 SomeService의 subclass를 검색하여 loader에 로드합니다.

  • 수정중
@wooyounggggg wooyounggggg self-assigned this Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant