프로그래밍 언어

DART 대충 빠르게 훝어본 C++과 다른점

소혼 2021. 1. 19. 07:53
반응형

타입

num 타입 : int 타입 + double 타입인듯
float은 안보임

auto 같은 var
as 로 타입변환이 되는데 0.1이 int가 되진 못함

타입검사
if (a is int) {...}
if (a is! int) {...}

연산자 https://dart.dev/guides/language/language-tour#operators

~/ : 몫 연산자가 있음 아무래도 int 타입때문인듯

- null aware operators

?? : if null operator : null인지 체크

// prefs.getBool('some-feature') 가 null이면 false 아니면 prefs.getBool('some-feature')
bool v = prefs.getBool('some-feature') ?? false;

??=  null aware assignment
?. null aware access
?... null aware spread operator [ Dart 2.3부터 ]

as, is, is! : 

 

함수

print('hello ${person.name}')

  • 함수의 선택 매개변수, 기본값
    void something(String name, {int age = 10}) {}

클래스

  • class의 private은 _으로 시작
  • getter setter
    int get age => _age;
    set age => _age;
  • 상속은 extends, abstract class는 implements, 상속하지 않고 가져오는 with
  • 오버라이드할때 메소드앞에는 @override

PS, 더 있을 수 있습니다.

반응형