-
Notifications
You must be signed in to change notification settings - Fork 5k
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
拥抱 Java 8 语言特性 #1963
拥抱 Java 8 语言特性 #1963
Conversation
为啥子这么多 commit 记录 |
下次记得翻译一篇新开一个分支,合并之后删除分支。master 分支用来同步,下次翻译再从 master 新开就好啦。#养成使用 Git 的好习惯# |
|
||
They are again syntactic sugar to simplify a lambda expression that invokes an existing method. They can reference to: | ||
它们是语法糖,可以简化调用了现有方法的 lambda 表达式。他们可以引用: |
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.
它们是语法糖 -> 它们同样是语法糖
|
||
Default methods make it possible to add new methods to an interface without breaking all classes that implement that interface. | ||
默认方法使你可以在不破坏实现一个接口的所有的类的情况下,向接口中加入新的方法。 |
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.
原文确实是通顺的,我觉得这边可能是要强调一下这个接口的“同一个”,并且下面半句里用了“该接口”,个人感觉这样可能更顺畅一点?
|
||
Default methods make it possible to add new methods to an interface without breaking all classes that implement that interface. | ||
默认方法使你可以在不破坏实现一个接口的所有的类的情况下,向接口中加入新的方法。 |
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.
向接口中加入新的方法 -> 向该接口中加入新的方法
|
||
Just use `alt/option` + `enter` to convert a functional interface to a lamba or a lambda to a method reference. | ||
只要使用 `alt/option` + `enter` 就可以把功能接口转化为一个 lambda,或把 lambda 转为方法引用。 |
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.
只要使用 alt/option
+ enter
就可以把功能接口转化为一个 lambda,或把 lambda 转为方法引用。 ->
只要使用 alt/option
+ enter
就可以把功能接口转化为一个 lambda 表达式,或把 lambda 表达式转为方法引用。
|
||
This is a great way to get familiar with these new features and allows you to write code like you’re used to. After enough quick fixes by Android Studio you’ll learn in what cases a lambda or method reference would be possible and start writing them yourself. | ||
这是一种熟悉新特性的好办法,它使你可以按照自己习惯的方式写代码。在使用 Android Studio 的快速修复功能足够多次之后,你将学会 lambda 和方法引用有哪些使用场景,并开始自己写它们。 |
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.
你将学会 lambda 和方法引用有哪些使用场景,并开始自己写它们。 ->
你将学会 lambda 表达式和方法引用有哪些使用场景,并开始自己写它们。
|
||
While not all Java 8 features have been backported yet, Android Studio 3.0 offers plenty more features: | ||
虽然并不是所有的 Java 8 特性都已经被向后移植,Android Studio 3.0 提供了很多其他的特性: |
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.
Android Studio 3.0 提供了很多其他的特性 -> 但是 Android Studio 3.0 仍然提供了很多其他的特性
- [repeating annotations](https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html) | ||
- [try with resources](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) (all versions, no longer min SDK 19) | ||
- [静态接口方法](https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html) | ||
- [类型标记](https://docs.oracle.com/javase/tutorial/java/annotations/type_annotations.html) |
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.
类型标记 -> 类型注解
@sqrthree @tanglie1993 一校完毕 翻译很棒 校对有些鸡蛋里头挑骨头 请见谅 |
@sqrthree 校对申请 |
@DeadLion 好哒 |
|
||
Recall that lambda expressions remove a lot of boilerplate code for functional interfaces. Method references take that concept one step further when the lambda calls a method that already has a name. | ||
回忆一下 lambda 表达式为功能接口删除了大量样板代码的情形。当 lambda 调用了已经有一个名字的方法时,方法引用把这个概念更推进了一步。 |
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.
调用了一个已经有名字的方法时
|
||
Default methods make it possible to add new methods to an interface without breaking all classes that implement that interface. | ||
默认方法使你可以在不破坏实现一个接口的所有的类的情况下,向接口中加入新的方法。 |
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.
可以在不破坏一个接口所有实现类的情况下
@@ -163,9 +163,9 @@ public class MyFragment implements MyView { | |||
} | |||
``` | |||
|
|||
When you now want to add an extra method to `MyView` your code will no longer compile, until `MyFragment` also implements that new method. This is annoying, and can be even problematic when many classes are implementing said interface. | |||
如果你现在想要向 MyView 中加入一个额外的方法,你的代码将不再能够编译,直到 `MyFragment` 同样实现了这个新方法。这很烦人,并且如果很多类都实现这个接口的话,可能会引发新的问题。 |
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.
你的代码将无法编译
|
||
While this all might seem a bit overwhelming, Android Studio actually offers amazing quick fixes once you enable Java 8 features. | ||
虽然这看起来有些吓人,但是一旦你打开了 Java 8 特性,Android Studio 就提供了非常好用的快速修复功能。 |
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.
虽然这么多东西可能让人有点无所适从,但是一旦你足够了解 Java 8 特性时,
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.
enable并没有“了解”的意思吧?
|
||
If you’ve made it this far, you should probably follow me on [Twitter](https://twitter.com/molsjeroen). Feel free leave a comment below! | ||
如果你已经读到这里了,你很可能应该在 [Twitter](https://twitter.com/molsjeroen) 上关注我。欢迎评论! |
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.
probably
@sqrthree @tanglie1993 校稿完成 |
@tanglie1993 两位校对者都已经校对好了~ 可以来根据校对意见进行调整了哈 ┏ (゜ω゜)=☞ |
好了。 |
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.
还有一些问题需要调整下哈。辛苦啦。
@@ -3,20 +3,20 @@ | |||
> * 原文作者:[Jeroen Mols](https://jeroenmols.com/) | |||
> * 译文出自:[掘金翻译计划](https://github.com/xitu/gold-miner) | |||
> * 本文永久链接:[https://github.com/xitu/gold-miner/blob/master/TODO/embracing-java-8-language-features.md](https://github.com/xitu/gold-miner/blob/master/TODO/embracing-java-8-language-features.md) | |||
> * 译者: | |||
> * 译者:[tanglie1993](https://github.com/tanglie1993) | |||
> * 校对者: |
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.
校对者信息要加一下啦
| instance method of object | myObject::doSomething | | ||
| constructor | MyClass:: new | | ||
| instance method of any argument type | String::compare | | ||
| 静态方法 | MyClass::doSomething | |
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.
这里应该是个表格,需要按照 Markdown 的语法调整一下哈。
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.
英文原文 是的,应该是在转化成 Markdown 的时候出现了失误。
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.
可是markdown支持这个样子的表格吗?
|
||
For more examples about this have a look at the [official documentation](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html). | ||
如果你需要更多关于这个的实例,请查看[官方文档](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html)。 |
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.
『官方文档』前面加个空格和其他地方保持一致哈。
- [静态接口方法](https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html) | ||
- [类型注解](https://docs.oracle.com/javase/tutorial/java/annotations/type_annotations.html) | ||
- [重复标记](https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html) | ||
- [针对资源的 try 语句](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) (all versions, no longer min SDK 19) |
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.
这句英文也应该翻译吧。
已经 merge 啦~ 快快麻溜发布到掘金专栏然后给我发下链接,方便及时添加积分哟。 |
@tanglie1993 反馈链接加积分啦 |
close #1959