-
Notifications
You must be signed in to change notification settings - Fork 1k
Simplify Chinese translation of Scala Tour: type-inference.md #1207
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
Conversation
1d31edd
to
7c05384
Compare
_zh-cn/tour/type-inference.md
Outdated
val q = id(1) // type: Int | ||
``` | ||
|
||
编译器使用参数 `MyPair` 的类型来推断出 `A` 和 `B` 的类型。对于 `x` 的类型同样如此。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
编译器使用传给MyPair
参数的类型
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot.
_zh-cn/tour/type-inference.md
Outdated
|
||
## 参数 | ||
|
||
编译器从不推断方法参数的类型。 但是,在某些情况下,当函数作为参数传递时,它可以推断出匿名函数参数类型。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
方法参数
->方法形式参数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
编译器可以推断出匿名函数形式参数的类型
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot.
_zh-cn/tour/type-inference.md
Outdated
Seq(1, 3, 4).map(x => x * 2) // List(2, 6, 8) | ||
``` | ||
|
||
方法 map 的参数是 `f: A => B`。 因为我们把整数放在 `Seq` 中,编译器知道 `A` 是 `Int` 类型 (即 `x` 是一个整数)。 因此,编译器可以从 `x * 2` 推断出 `B` 是 `Int` 类型。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
形式参数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot.
_zh-cn/tour/type-inference.md
Outdated
|
||
## 何时 _不要_ 依赖类型推断 | ||
|
||
通常认为声明在公共 API 中的成员类型更具可读性。 因此,我们建议你为将在你的代码中向用户公开的任何 API 明确指定类型。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通常认为,公开可访问的 API 成员应该具有显示类型声明。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot.
_zh-cn/tour/type-inference.md
Outdated
var obj = null | ||
``` | ||
|
||
我们就不能继续重新分配值: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们就不能进行重新赋值:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's much better, thanks a lot.
…ing to liufengyu's suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the contribution @realwunan 🎉
Simplify Chinese translation of Scala Tour: Type Inference