2020년인데 자바8의 새로운 기능을 몰라요?(8) 유원 구조 코드 분석과 총결
공부하고 까먹었어. 어떡해?기록해 두다.블로그를 필기하다.억지로 외우는 것은 아무 소용이 없다.
ReferencePipeline
/**
* Abstract base class for an intermediate pipeline stage or pipeline source
* stage implementing whose elements are of type {@code U}.
*/
//
//ReferencePipeline 。
//ReferencePipeline.head 。
abstract class ReferencePipeline
extends AbstractPipeline>
implements Stream {
}
AbstractPipeline
/**
* Abstract base class for "pipeline" classes, which are the core
* implementations of the Stream interface and its primitive specializations.
* Manages construction and evaluation of stream pipelines.
*
* An {@code AbstractPipeline} represents an initial portion of a stream
* pipeline, encapsulating a stream source and zero or more intermediate
* operations. The individual {@code AbstractPipeline} objects are often
* referred to as stages, where each stage describes either the stream
* source or an intermediate operation.
。
*
*
A concrete intermediate stage is generally built from an
* {@code AbstractPipeline}, a shape-specific pipeline class which extends it
* (e.g., {@code IntPipeline}) which is also abstract, and an operation-specific
* concrete class which extends that. {@code AbstractPipeline} contains most of
* the mechanics of evaluating the pipeline, and implements methods that will be
* used by the operation; the shape-specific classes add helper methods for
* dealing with collection of results into the appropriate shape-specific
* containers.
* 。
*
After chaining a new intermediate operation, or executing a terminal
* operation, the stream is considered to be consumed, and no more intermediate
* or terminal operations are permitted on this stream instance.
* , 。 。
* @implNote
*
For sequential streams, and parallel streams without
* stateful intermediate
* operations, parallel streams, pipeline evaluation is done in a single
* pass that "jams" all the operations together. For parallel streams with
* stateful operations, execution is divided into segments, where each
* stateful operations marks the end of a segment, and each segment is
* evaluated separately and the result used as the input to the next
* segment. In all cases, the source data is not consumed until a terminal
* operation begins.
, 。
* @param type of input elements
* @param type of output elements
* @param type of the subclass implementing {@code BaseStream}
* @since 1.8
*/
abstract class AbstractPipeline>
extends PipelineHelper implements BaseStream {
}
내부 클래스와 lambda 표현식 간의 관계.
본질적으로 내부류와 lambda는 같은 것이 아니다.단지 같은 조작을 완성할 수 있을 뿐이다.
lambda는 익명 내부류의 문법사탕이나 줄임말이 아니다.일종의 새로운 형식이다.
public class LambdaTest {
// , lambda 。
Runnable r1 = () -> System.out.println(this); // this
//
Runnable r2 = new Runnable() { //
@Override
public void run() {
System.out.println(this);
// this
}
};
public static void main(String[] args) {
LambdaTest lambdaTest = new LambdaTest();
Thread t1 = new Thread(lambdaTest.r1);
t1.start();
System.out.println("- - -- - ");
Thread t2 = new Thread(lambdaTest.r2);
t2.start();
// 。
//com.sinosoft.lis.test.LambdaTest@62661526
//com.sinosoft.lis.test.LambdaTest$1@59a30351
}
}
템플릿 메소드 모드를 사용했습니다.
흐름은 타성이고 조작을 지연시킨다.작업이 종료될 때까지 작업을 수행하지 않습니다.
TerminalOp. 작업을 중지하는 인터페이스 클래스입니다.
종료 작업은 4가지 유형, findOp foreachOp matchOp reduceOp
PipelineHelper
stream 중간 조작 및 정지 조작 차원 체계 분석 및 디자인 사상 분석
중간 조작
BaseStream -》 AbStractpipeline -》ReferencePipeline -》 Head || StatelessOP || statefulOp
맨 윗부분의 원천이 매우 많은 구성원 변수 파이프 구조 유원 무상태 중간 조작 유상태 중간 조작
흐름은 타성이고 조작을 지연시킨다.작업이 종료될 때까지 작업을 수행하지 않습니다.작업이 종료되기 전에 중간 작업(Sink)을 통합합니다.
작업 종료
TerminalOp -》 FindOp || ForeachOp || MatchOp || reduceOp
맨 윗층의
TerminalSink
중지된 물탱크.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.