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

关于在泛型笔记的问题 #18

Open
stormGa opened this issue Jan 24, 2019 · 0 comments
Open

关于在泛型笔记的问题 #18

stormGa opened this issue Jan 24, 2019 · 0 comments

Comments

@stormGa
Copy link

stormGa commented Jan 24, 2019

        int a = biggerOne(3,5);
        //int 和 double,取交为Number
        Number b = biggerOne(3,5.5);
        System.out.println(b.getClass().getName());
        //String和int 取交为Object
        Object c = biggerOne("1",2);``

关于为什么b是Double类型的猜测。
这应该是多态,类如Number b = new Double();
而为什么将Number改为Double报错,应该是因为泛型T可能的值有两个int和double,做了类型限制,这样代码更加灵活,出错率低。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant