提交 11249b1c 编写于 作者: M Mars Liu

sam

上级 dfcfed12
无相关合并请求
{
"node_id": "java-0a39f4040da04b8591f9b36f3c446789",
"keywords": [],
"children": [
{
"初试牛刀:筛选绿苹果": {
"keywords": [],
"children": [],
"node_id": "java-e888465b1043473fbb919fd4958e3179",
"title": "初试牛刀:筛选绿苹果"
}
},
{
"再展身手:把颜色作为参数": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "再展身手:把颜色作为参数"
}
},
{
"第三次尝试:对你能想到的每个属性做筛选": {
"keywords": [],
"children": [],
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"title": "第三次尝试:对你能想到的每个属性做筛选"
}
}
],
"export": [],
"title": "应对不断变化的需求"
}
\ No newline at end of file
......@@ -34,6 +34,6 @@
}
}
],
"export": [],
"export": ["sam.json"],
"title": "对付啰唆"
}
\ No newline at end of file
# Single Abstract Method
下面哪一个类型定义,在构造其对象时,可以简化为 lambda?
## 答案
```java
public interface Parsec<E, T> {
default T ask(State<E> state) {
try {
return new Success(this.parse(state));
} catch (Exception error){
return new Failure(error);
}
}
T parse(State<E> state);
}
```
## 选项
### SAM 需要 interface
```java
public abstract class Element {
String read();
void write(String content);
}
```
### 有两个未定义方法
```java
public interface Element {
String read();
void write(String content);
}
```
### 没有抽象方法,无法按 SAM 处理
```java
public class Cell {
String content;
public Cell(String content){
this.content = content;
}
public String text() {
return content;
}
public String text(String content){
this.content = content;
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部