48 lines
1013 B
Markdown
48 lines
1013 B
Markdown
---
|
|
parents:
|
|
- "[[Вопросы для собеседование Java]]"
|
|
---
|
|
```java
|
|
private static void show(boolean flag, int experience) {
|
|
if (flag) {
|
|
experience = 1;
|
|
}
|
|
IntStream
|
|
.range(0, experience)
|
|
.forEach(i -> System.out.println(experience + i));
|
|
}
|
|
```
|
|
|
|
%%
|
|
```java
|
|
package dev.struchkov.example;
|
|
|
|
public class Main {
|
|
|
|
public static void main(String[] args) {
|
|
Main application = new Main();
|
|
final Displaying displaying = application.calculate(2, 3, Operation.ADD);
|
|
displaying.show();
|
|
}
|
|
|
|
public Displaying calculate(int a, int b, Operation operation) {
|
|
int result = 0;
|
|
switch (operation) {
|
|
case ADD -> result = a + b;
|
|
case SUB -> result = a - b;
|
|
}
|
|
return () -> System.out.println(result);
|
|
}
|
|
|
|
}
|
|
|
|
interface Displaying {
|
|
void show();
|
|
}
|
|
|
|
enum Operation {
|
|
ADD, SUB
|
|
}
|
|
```
|
|
Variable used in lambda expression should be final or effectively final
|
|
%% |