본문 바로가기
반응형

다트3

[Dart] non nullable 변수의 초기화 시기 https://dart.dev/null-safety/understanding-null-safety Understanding null safety A deep dive into Dart language and library changes related to null safety. dart.dev 공식문서 null safety의 이해에서 발췌, Uninitialized variables항목 참고 1. 개요 Dart의 non nullable 변수는 사용전에 반드시 초기화 해 주어야 한다. 그런데 코드를 작성하다보면 사용전에만 초기화 하면 될 줄 알았는데 어떤 경우에는 선언과 동시에 초기화를 해야하는 경우가 있다. 어떨때는 나중에 초기화해도 되고, 어떨때는 반드시 선언과 동시에 초기화 해야하는데 이 문서는 이를.. 2022. 6. 10.
[Dart] late변수 사용 시기, nullable변수와의 차이 https://dart.dev/null-safety/understanding-null-safety#smarter-null-aware-methods Understanding null safety A deep dive into Dart language and library changes related to null safety. dart.dev 해당 블로그 내용은 null safety에 대한 이해에서 발췌 해 왔음 1. 개요 다트에서는 late변수를 제공한다. late변수를 사용하면 non-nullable변수의 초기화를 나중에 할 수 있다. 헌데 한가지 의문점이 있다. 변수의 자료형을 nullable로 선언해도 나중에 초기화를 할 수 있으니 그냥 nullable을 쓰면 되지 왜 굳이 구글은 late라는 키워.. 2022. 6. 9.
Dart의 선택적 매개변수 뭐하는거임? 자바에서 생성자를 만들때 여러개 만들던 기억이 남? Class ABC{ int A; int B; int C; ABC(int a){ this.A =a; } ABC(int a,int b){ this.A = a; this.B = b; } ABC(int a,int b,int c){ this.A = a; this.B = b; this.C = c; } } 저 망할 오버로딩 반복하는 작업을 줄이기 위해 만든거임 아래는 dart 코드로 만들어진 생성자 Class ABC({this.A = 0, this.B = 0, this.C = 0}); 사용법은 아래와 같다 생성자({ this.변수 = 초기값, this.변수 = 초기값, .....}) 그럼 아래와 같이 객체생성이 가능하다 ABC({A: 10}); ABC(.. 2021. 7. 20.
반응형