-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTesteThread.java
More file actions
49 lines (35 loc) · 1.05 KB
/
Copy pathTesteThread.java
File metadata and controls
49 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
import java.util.functions.*;
import static java.lang.System.out;
/**
* Exemplo de outras alternativas para o uso de expressoes lambda.
*/
public class TesteThread {
public static void main(String args[]){
String msg = "Runnable em lambda expression ";
//metodo void
new Thread(() -> { out.println("Runnable em lambda expression "); }).start();
new Thread(newRun("outra thread...")).start();
new TesteThread().useThis();
changeContent(msg);
}
public String toString() {
return "toString de TesteThread";
}
//metodo retorna lambda
static Runnable newRun(String content){
return () -> { out.println("Runnable em lambda expression "); };
}
//metodo utilizando this (referencia para TesteThread)
void useThis() {
new Thread(() -> { out.println(this); }).start();
}
//lambdas sao objetos imutaveis
static void changeContent(String s) {
//nao compila
//new Thread(() -> { s = "Outro"; }).start();
}
}
//usar string
//criar um metodo que retorna thread...
//criar um metodo que usa utiliza this (n static)