ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 16 TIL // 예비군
    내일배움캠프 2022. 11. 18. 21:04

     

    국방의 의무를 다한 날입니다.

     

     

    Generics
    다양한 타임의 객체들을 다루는 method, collection class에 컴파일 시 type 체크 해주는 기능

    public class Main {
        public static void main(String[] args) {
    
            // 잘 모르겠으니 나중에 다시 한벅 확인 1-24
    
            List<String> list = new ArrayList();
            list.add("string")
            Collection<String> collection = list;
    
            List<Exception> exceptionList = new ArrayList<>();
            Collection<Exception> exceptionCollection =exceptionList;
    
            List<IllegalArgumentException> exceptions =new ArrayList<>(); // Exception 자식 클래스
            exceptionCollection.addAll(exceptions);
    
        }
    }



    Lamba 

    public, void, method name () 등.. 없이 함수를 정의하고 실행 할 수 있는 함수
    단점 : 코드가 간편해지지만 함수 정의가 아니라 중복된 코드가 많아지면서 지저분해짐

    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.List;
    import java.util.stream.Stream;
    
    public class Main {
        public static void main(String[] args) {
            List<String> list = new ArrayList<>();
            list.add("korea");
            list.add("japan");
            list.add("france");
            Stream<String> straam = list.stream();
            straam.map(str -> str.toUpperCase()).forEach(System.out::println);
         // Stream: 하나씩 꺼내줌 map: 앞에 값을 어떻게 바꿀게, toUpperCase(): 대문자로 바꿔줌,   .forEach: 각각 해당 구문 실행
        }
    }

     

    '내일배움캠프' 카테고리의 다른 글

    18 TIL  (0) 2022.11.22
    17 TIL  (0) 2022.11.21
    15 TIL  (0) 2022.11.17
    14 TIL  (0) 2022.11.16
    13 TIL  (0) 2022.11.15
Designed by Tistory.