728x90 NULL2 코틀린 null 처리 package nullsafe fun main() { testFun1("문자열") //컴파일 에러가 아닌 런타임 에러이다 // testFun1(null) testFun2("문자열") testFun2(null) testFun3("문자열") testFun3(null) testMethod1("안녕하세요") testMethod1(null) testMehod2("안뇽") testMehod2(null) } // !! 널을 허용하지 않는 변수에 널을 허용하는 변수를 담아준다 // 되도록 사용하지 말자 fun testFun1(str:String?){ val value1:String = str!! println("value1 = ${value1}") } // ? 연산자 // null일 경우 뒤에 값 default로 사용.. 2022. 5. 25. @Autowired 옵션 해당 옵션 적용시 해당 빈 객체 없어도 오류 안남 static class TestBean { @Autowired(required = false) public void setNoBean(Member noBean1) { System.out.println("noBean1 = " + noBean1); } @Autowired public void setNoBean2(@Nullable Member noBean1) { System.out.println("noBean1 = " + noBean1); } @Autowired public void setNoBean3(Optional noBean3) { System.out.println("noBean3 = " + noBean3); } } 2021. 8. 13. 이전 1 다음 728x90