[Flutter] .. cascade notation 이게 뭘까?

kimdocs...📄·2023년 11월 27일
0

flutter

목록 보기
18/30

.. 문법은 Dart에서 "cascade notation" 또는 "cascade operator"라고 불리며, 여러 메소드 호출을 한 번의 객체에 연속적으로 적용할 수 있게 해준다. 이것은 객체를 초기화하고 설정하는 데 편리한 방법.

class Person {
  String name = '';
  int age = 0;
}

void main() {
  final person = Person()
    ..name = 'John' // 객체를 초기화하고 속성을 설정하는 예제
    ..age = 30;
  
  print('Name: ${person.name}, Age: ${person.age}');
}
profile
👩‍🌾 GitHub: ezidayzi / 📂 Contact: ezidayzi@gmail.com

0개의 댓글