brianway / brianway/java-learning

关于在泛型笔记的问题

Open
#18 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
4.3k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

```
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,做了类型限制,这样代码更加灵活,出错率低。

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate the definition of biggerOne and the surrounding Java generics notes or examples. Compare the calls using int, double, and String arguments, then verify the documented explanation against the observed return types. Done means the question is answered clearly in the relevant learning material, with any needed example or clarification included.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.