Skip to content

Commit ea63716

Browse files
committed
feat(lambda): 🎸 functional interfaces, translated
Refers: #6
1 parent 54cd157 commit ea63716

9 files changed

+77
-77
lines changed
Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,57 @@
11
:java-package: src/org/j6toj8/lambda
22
:section-java-package: ../../../{java-package}
33

4-
=== Interfaces Funcionais (Functional Interfaces)
4+
=== Functional Interfaces
55

6-
.Objetivo
6+
.Objective
77
--------------------------------------------------
88
Define and write functional interfaces and describe the interfaces of the java.util.function package.
9-
-
10-
Definir e escrever interfaces funcionais e descrever as interfaces do pacote java.util.function.
119
--------------------------------------------------
1210

13-
Interfaces funcionais são um novo tipo de Interface do Java. Nesta seção serão apresentados os conceitos e na seção de <<book/04-lambda/sections/02-lambda-expression.asc#lambda-expression,Expressões Lambda>> será possível ver como utilizá-las.
11+
Functional interfaces are a new type of Java Interface. In this section the concepts will be presented and in the <<book/04-lambda/sections/02-lambda-expression.asc#lambda-expression,Lambda Expressions>> section you will see how to use them.
1412

15-
. Interfaces Funcionais são aquelas que possuem apenas um método abstrato, chamado de "método funcional".
16-
. É recomendada a utilização da anotação `@FunctionalInterface`, mas não obrigatório.
13+
. Functional Interfaces are those that have only one abstract method, called the "functional method".
14+
. The use of the `@FunctionalInterface` annotation is recommended, but not required.
1715
+
1816
[source,java,indent=0]
1917
.{java-package}/functionalinterfaces/FunctionalInterfaces_Basic.java
2018
----
2119
include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_Basic.java[tag=code]
2220
----
2321
+
24-
A anotação `@FunctionalInterface` garante, em tempo de compilação, que esta interface é funcional. Também indica para outros desenvolvedores que ela foi criada com o intuito de ser utilizada em expressões lambda, e por isso não se deve criar outros métodos abstratos dentro dela.
22+
The `@FunctionalInterface` annotation ensures at compile time that this interface is functional. It also indicates to other developers that it was created for use in lambda expressions, so you should not create other abstract methods within it.
2523

26-
. Métodos adicionais que sejam `default` ou `static` não fazem com que a interface deixe de ser funcional.
24+
. Additional methods that are `default` or `static` don't make the interface to be functional.
2725
+
2826
[source,java,indent=0]
2927
.{java-package}/functionalinterfaces/FunctionalInterfaces_DefaultStatic.java
3028
----
3129
include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_DefaultStatic.java[tag=code]
3230
----
3331
+
34-
Lembre-se que os métodos `static` em interfaces podem ser chamados diretamente, como `Executavel.execute(...)`. Dessa forma, não há interferência no fato da interface ser funcional.
32+
Remember that `static` methods on interfaces can be called directly, such as `Executable.execute (...)`. Thus, there is no interference in the fact that the interface is functional.
3533
+
36-
Por outro lado, os métodos `default` só podem ser chamados caso você possua uma instância da interface, porém eles já possuem uma implementação padrão.
34+
On the other hand, `default` methods can only be called if you have an instance of the interface, but they already have a default implementation.
3735
+
38-
Em caso de dúvidas sobre `static` ou `default` em interfaces, volte na seção de "Métodos _static_ e _default_ em Interfaces".
36+
If you have questions about `static` or `default` in interfaces, go back to the _"Static and default methods of an interface"_ section.
3937

40-
. Sobrescrever na interface um método público de `java.lang.Object` também não faz com que ela deixe de ser funcional.
38+
. Overriding a public method of `java.lang.Object` in the interface doesn't turn it to a no functional interface.
4139
+
4240
[source,java,indent=0]
4341
.{java-package}/functionalinterfaces/FunctionalInterfaces_OverrideObject.java
4442
----
4543
include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_OverrideObject.java[tag=code]
4644
----
4745

48-
. Uma interface que estende outra sem acrescentar métodos abstratos também pode ser funcional.
46+
. An interface that extends another without adding abstract methods can also be functional.
4947
+
5048
[source,java,indent=0]
5149
.{java-package}/functionalinterfaces/FunctionalInterfaces_Extends.java
5250
----
5351
include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_Extends.java[tag=code]
5452
----
5553

56-
. Se uma interface estende outra que é funcional, porém acrescenta novos métodos abstratos, ela não é funcional.
54+
. If one interface extends another that is functional but adds new abstract methods, it is not functional.
5755
+
5856
[source,java,indent=0]
5957
.{java-package}/functionalinterfaces/FunctionalInterfaces_ExtendsNewMethod.java
@@ -69,68 +67,68 @@ include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_Extend
6967
include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_InterfaceCompilationError.java[tag=code]
7068
----
7169

72-
. Utilizar a anotaçao `@FunctionalInterface` em qualquer tipo que não seja uma interface causa um erro de compilação.
70+
. Using the `@FunctionalInterface` annotation on any type other than an interface causes a compilation error.
7371
+
7472
[source,java,indent=0]
7573
.{java-package}/functionalinterfaces/FunctionalInterfaces_ClassCompilationError.java
7674
----
7775
include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_ClassCompilationError.java[tag=code]
7876
----
7977

80-
. Os métodos funcionais podem ter qualquer tipo de retorno.
78+
. Functional methods can have any return.
8179
+
8280
[source,java,indent=0]
8381
.{java-package}/functionalinterfaces/FunctionalInterfaces_ReturnType.java
8482
----
8583
include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_ReturnType.java[tag=code]
8684
----
8785

88-
. Interfaces funcionais são feitas com o intuito de serem utilizadas em expressões lambda, mas o código também irá compilar normalmente caso uma classe a implemente.
86+
. Functional interfaces are meant to be used in lambda expressions, but the code will also compile normally if a class implements it.
8987
+
9088
[source,java,indent=0]
9189
.{java-package}/functionalinterfaces/FunctionalInterfaces_Implement.java
9290
----
9391
include::{section-java-package}/functionalinterfaces/FunctionalInterfaces_Implement.java[tag=code]
9492
----
9593
+
96-
Esse é apenas um exemplo para você saber que essa implementação não gera erro de compilação, mas *não* utilize interfaces funcionais dessa forma. Na seção de Expressões Lambda você verá como as interfaces funcionais devem ser utilizadas na prática.
94+
This is just an example for you to know that this implementation does not generate compilation errors, but *does not* use functional interfaces in this way. In the Lambda Expressions section, you will see how functional interfaces should be used in practice.
9795

98-
==== Interfaces Funcionais do pacote `java.util.function`
96+
==== Functional Interfaces from `java.util.function` package
9997

100-
As interfaces descritas aqui estão disponíveis no pacote `java.util.function`. Nesta seção serão apresentadas apenas suas definições, pois há posteriormente uma seção específica para tratar dos exemplos de cada uma.
98+
The interfaces described here are available in the `java.util.function` package. This section will present only its definitions, as there is later a specific section to deal with the examples of each.
10199

102-
Existem outras interfaces nesse pacote além das listadas aqui, porém são apenas específicas para lidar com tipos primitivos, seguindo as mesmas definições.
100+
There are other interfaces in this package besides those listed here, but they are only specific to dealing with primitive types, following the same definitions.
103101

104-
* `Supplier<T>`: Representa um fornecedor de resultados.
102+
* `Supplier<T>`: Represents a results provider.
105103
+
106-
Um `Supplier` literalmente apenas fornece dados ou resultados para alguém. Um gerador de números sequenciais, por exemplo, pode ser um `Supplier`.
104+
A `Supplier` literally only provides data or results to someone. A sequential number generator, for example, may be a `Supplier`.
107105

108-
* `Consumer<T>`: Representa uma operação que aceita uma única entrada e não possui retorno.
109-
* `BiConsumer<T,U>`: Representa uma operação que aceita duas entradas e não possui retorno.
106+
* `Consumer<T>`: Represents an operation that accepts a single entry and has no return.
107+
* `BiConsumer<T, U>`: Represents an operation that accepts two inputs and has no return.
110108
+
111-
Os `Consumer` são praticamente o inverso dos `Supplier`, pois eles apenas recebem dados ou informações e os tratam de alguma forma.
109+
`Consumers` are pretty much the opposite of `Supplier`, as they only receive data or information and treat them in some way.
112110

113-
* `Function<T,R>`: Representa uma função que aceita um argumento e produz um retorno.
114-
* `BiFunction<T,U,R>`: Representa uma função que aceita dois argumentos e produz um retorno.
111+
* `Function<T, R>`: Represents a function that accepts an argument and produces a return.
112+
* `BiFunction<T, U, R>`: Represents a function that takes two arguments and produces a return.
115113
+
116-
As `Function` são mais parecidas com as funções que já conhecemos. Elas recebem dados e produzem um retorno.
114+
The `Function` are more similar to the functions we already know. They receive data and produce a return.
117115

118-
* `Predicate<T>`: Representa uma proposição (função de valor booleano) de um argumento.
119-
* `BiPredicate<T,U>`: Representa uma proposição (função de valor booleano) de dois argumentos.
116+
* `Predicate<T>`: Represents a proposition (Boolean value function) of an argument.
117+
* `BiPredicate<T, U>`: Represents a proposition (Boolean value function) of two arguments.
120118
+
121-
Os `Predicate` são parecidos com as `Function`, porém sempre retornam um resultado booleano, por isso são utilizados para "testes" de verdadeiro ou falso.
119+
`Predicate` is similar to `Function`, but always returns a Boolean result, so it is used for true or false "tests".
122120

123-
* `UnaryOperator<T>`: Representa uma operação em um único operador que produz um resultado do mesmo tipo dele.
124-
* `BinaryOperator<T>`: Representa uma operação em dois operadores que produz um resultado do mesmo tipo deles.
121+
* `UnaryOperator<T>`: Represents an operation on a single operator that produces a result of the same type as it.
122+
* `BinaryOperator<T>`: Represents an operation on two operators that produces a result of the same type as them.
125123
+
126-
Os `Operator` são especializações de `Function`, pois apesar de também sempre recebem e produzirem resultados, as entradas e saídas são sempre do mesmo tipo.
124+
The `Operator` are `Function` specializations, because although they also always receive and produce results, the inputs and outputs are always the same type.
127125

128-
.Referências
126+
.References
129127
****
130128
131129
* Introducing Functional Programming
132130
+
133-
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 52). Wiley. Edição do Kindle.
131+
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 52). Wiley. Kindle Edition.
134132
135133
* https://www.baeldung.com/java-8-functional-interfaces[Functional Interfaces in Java 8.]
136134
@@ -140,4 +138,4 @@ Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8
140138
141139
* https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html[Lambda Expressions.] The Java™ Tutorials.
142140
143-
****
141+
****

src/org/j6toj8/lambda/functionalinterfaces/FunctionalInterfaces_Basic.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
public class FunctionalInterfaces_Basic {
44

55
// tag::code[]
6-
@FunctionalInterface // a anotação não é obrigatória
7-
interface Executavel { // interface funcional
8-
void execute(); // método funcional
6+
@FunctionalInterface // annotation is not required
7+
interface Executavel { // functional interface
8+
void execute(); // functional method
99
}
1010
// end::code[]
1111
}

src/org/j6toj8/lambda/functionalinterfaces/FunctionalInterfaces_ClassCompilationError.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ public class FunctionalInterfaces_ClassCompilationError {
44

55
// tag::code[]
66
@FunctionalInterface
7-
interface Executavel { // interface funcional
8-
void execute(); // método funcional
7+
interface Executable { // functional interface
8+
void execute(); // functional method
99
}
1010

1111
@FunctionalInterface
12-
class Piloto { // NÃO COMPILA!
13-
// apenas interfaces podem ser anotadas com @FunctionalInterface
12+
class Pilot { // NOT COMPILING!
13+
// only interfaces can be annotated with @FunctionalInterface
1414
}
1515
// end::code[]
1616
}

src/org/j6toj8/lambda/functionalinterfaces/FunctionalInterfaces_DefaultStatic.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ public class FunctionalInterfaces_DefaultStatic {
44

55
// tag::code[]
66
@FunctionalInterface
7-
interface Executavel { // interface funcional
8-
void execute(); // método funcional
7+
interface Executable { // functional interface
8+
void execute(); // functional method
99

10-
// métodos adicionais static são permitidos
11-
static void execute(Executavel... executaveis) {
12-
for (Executavel executavel : executaveis) {
13-
executavel.execute();
10+
// additional static methods are allowed
11+
static void execute(Executable... executables) {
12+
for (Executable executable : executables) {
13+
executable.execute();
1414
}
1515
}
1616

17-
// métodos adicionais default são permitidos
18-
default void executeDuasVezes() {
17+
// additional default methods are allowed
18+
default void executeTwice() {
1919
execute();
2020
execute();
2121
}

src/org/j6toj8/lambda/functionalinterfaces/FunctionalInterfaces_Extends.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ public class FunctionalInterfaces_Extends {
44

55
// tag::code[]
66
@FunctionalInterface
7-
interface Executavel { // interface funcional
8-
void execute(); // método funcional
7+
interface Executable { // functional interface
8+
void execute(); // functional method
99
}
1010

1111
@FunctionalInterface
12-
interface Aplicacao extends Executavel {
13-
// também é uma interface funcional
12+
interface Application extends Executable {
13+
// It is also a functional interface
1414
}
1515
// end::code[]
1616
}

src/org/j6toj8/lambda/functionalinterfaces/FunctionalInterfaces_ExtendsNewMethod.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ public class FunctionalInterfaces_ExtendsNewMethod {
44

55
// tag::code[]
66
@FunctionalInterface
7-
interface Executavel { // interface funcional
8-
void execute(); // método funcional
7+
interface Executable { // functional interface
8+
void execute(); // functional method
9+
}
10+
11+
@FunctionalInterface
12+
interface Application extends Executable {
13+
// It is NOT a functional interface as it has 2 abstract methods: execute (inherited) and init.
14+
void init();
915
}
10-
11-
interface Aplicacao extends Executavel {
12-
// NÃO é uma interface funcional, pois possui 2 métodos abstratos: execute (herdado) e inicie.
13-
void inicie();
14-
}
1516
// end::code[]
1617
}

src/org/j6toj8/lambda/functionalinterfaces/FunctionalInterfaces_Implement.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ public class FunctionalInterfaces_Implement {
44

55
// tag::code[]
66
@FunctionalInterface
7-
interface Executavel { // interface funcional
8-
String execute(); // método funcional
7+
interface Executable { // functional interface
8+
String execute(); // functional method
99
}
1010

11-
class Pessoa implements Executavel {
12-
// COMPILA!
13-
// interfaces funcionais, como Corredor, não foram feitas para serem implementadas dessa forma
14-
// porém é possível e o código compila normalmente
11+
class Person implements Executable {
12+
13+
// COMPILES!
14+
// functional interfaces, such as Executable, were not meant to be implemented this way but they are possible, and code compiles normally.
15+
1516
@Override
1617
public String execute() {
17-
return "Executando";
18+
return "Executing";
1819
}
1920
}
2021
// end::code[]

src/org/j6toj8/lambda/functionalinterfaces/FunctionalInterfaces_OverrideObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ public class FunctionalInterfaces_OverrideObject {
44

55
// tag::code[]
66
@FunctionalInterface
7-
interface Executavel { // interface funcional
8-
void execute(); // método funcional
7+
interface Executable { // functional interface
8+
void execute(); // functional method
99

10-
// sobrescrevendo métodos de Object
10+
// overriding Object methods
1111
@Override
1212
String toString();
1313
@Override

src/org/j6toj8/lambda/functionalinterfaces/FunctionalInterfaces_ReturnType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ public class FunctionalInterfaces_ReturnType {
44

55
// tag::code[]
66
@FunctionalInterface
7-
interface Executavel { // interface funcional
8-
String execute(); // método funcional com retorno
7+
interface Executable { // functional interface
8+
String execute(); // functional interface with return
99
}
1010
// end::code[]
1111
}

0 commit comments

Comments
 (0)