在React中,这两个实现之间是否存在真正的差异?有些朋友告诉我,FirstComponent是模式,但我不明白为什么.SecondComponent似乎更简单,因为渲染只被调用一次.
第一:
import React, { PropTypes } from 'react'
class FirstComponent extends React.Component {
state = {
description: ''
}
componentDidMount() {
const { description} = this.props;
this.setState({ description });
}
render () {
const {state: { description }} = this;
return (
<input type="text" value={description} />
);
}
}
export default FirstComponent;
Run Code Online (Sandbox Code Playgroud)
第二:
import React, { PropTypes } from 'react'
class SecondComponent extends React.Component {
state = {
description: ''
}
constructor (props) => {
const { description } …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用流来获取int数组的最小值,我正在尝试执行以下操作:
public static int smallestInt(int[] args) {
return Arrays.stream((Arrays.stream(args)
.boxed().toArray( Integer[]::new ))
.mapToInt(Integer::intValue).min().getAsInt;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是最好的方法是什么?
PS:有一个类似的问题,但这里没有sterams 使用Java查找基元数组中的最大/最小值