Stream.of()

cornpip·2023년 5월 24일
0

자바

목록 보기
1/19
post-thumbnail

Stream.of

    Stream<int[]> stream = Stream.of(new int[3]);
    Stream<char[]> stream1 = Stream.of(new char[3]);
    
    public static<T> Stream<T> of(T t) {
        return StreamSupport.stream(new Streams.StreamBuilderImpl<>(t), false);
    }

위의 Stream.ofStreamSupport.stream과 이어진다.

    Stream<Car> carStream = Stream.of(new Car[3]);
    Stream<String> stringStream = Stream.of(new String[3]);
    
    @SafeVarargs
    @SuppressWarnings("varargs") // Creating a stream from an array is safe
    public static<T> Stream<T> of(T... values) {
        return Arrays.stream(values);
    }

위의 Stream.ofArrays.stream 과 이어진다.
... values는 가변인자로 들어옴을 뜻하고 호출함수는 T[] v = values; 다음의 형태로 받는 듯 하다.

오버로딩으로 동작하는 건데 원시타입Array 생성자와 참조타입Array 생성자가 다르다?


일단 원시타입은 배열을 유지한채로 들어오고 참조타입은 배열을 벗기고 들어온다.

profile
https://cornpip.tistory.com 티스토리로 이전했습니다!

0개의 댓글