저는 대학의 초보 Java 프로그래머입니다. 저는 오늘 Java 구문이 작동하는 방식에 대한 제 개념 중 하나를 깨뜨린 것을 발견했습니다.
public class testClass {
ArrayList <String> persons = new ArrayList <String> ();
public void run(){
Stream <String> personstream = persons.stream();
}}
이 메서드 stream()
는 ArrayList
클래스 에서 찾을 수 없지만 마치있는 것처럼 나타날 수 있습니다. stream()
Eclipse 에서 -method 위로 마우스를 이동하면 Collections의 일부라고 표시되지만 stream()
온라인 문서에서 해당 메서드를 찾을 수 없습니다 .
stream()
내가 호출하는 클래스의 일부가 아닌 경우 메서드 를 호출하는 것이 작동하는 이유는 무엇 입니까?
올바른 클래스와 Java 버전을 확인 했습니까? 자바 (8)의은 Collection
(하지 Collections
)를 가지고 stream()
기본 방법 , 상속ArrayList
:
/**
* Returns a sequential {@code Stream} with this collection as its source.
*
* <p>This method should be overridden when the {@link #spliterator()}
* method cannot return a spliterator that is {@code IMMUTABLE},
* {@code CONCURRENT}, or <em>late-binding</em>. (See {@link #spliterator()}
* for details.)
*
* @implSpec
* The default implementation creates a sequential {@code Stream} from the
* collection's {@code Spliterator}.
*
* @return a sequential {@code Stream} over the elements in this collection
* @since 1.8
*/
default Stream<E> stream() {
return StreamSupport.stream(spliterator(), false);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다