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

Router.getInstance().getService()返回值能否改成泛型? #69

Open
liyujiang-gzu opened this issue Apr 19, 2019 · 0 comments
Open

Comments

@liyujiang-gzu
Copy link

Router.getInstance().getService()返回值能否改成泛型?不然每次都得显式强制类型转换:

Object service = Router.getInstance().getService(...);
if (service != null) {
    IXXXService xxxService = (IXXXService) service;
}

改为泛型类型后自动隐式强转:

    public synchronized <T> T getService(String serviceName) {
        if (serviceName == null) {
            return null;
        }
        return (T) services.get(serviceName);
    }
IXXXService xxxService = Router.getInstance().getService(...);
if (service != null) {
    ...
}
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

2 participants