정적 블록
정적 블록을 사용하면 해당 클래스 내의 private
필드에 접근할 수 있는 자체 범위가 있는 일련의 명령문을 작성할 수 있습니다. 즉, 명령문 작성의 모든 기능을 사용하고, 변수 누락 없이, 클래스 내부에 대한 완전한 접근 권한을 가지고, 초기화 코드를 작성할 수 있습니다.
ts
classFoo {static #count = 0;getcount () {returnFoo .#count;}static {try {constlastInstances =loadLastInstances ();Foo .#count +=lastInstances .length ;}catch {}}}
ts
classFoo {static #count = 0;getcount () {returnFoo .#count;}static {try {constlastInstances =loadLastInstances ();Foo .#count +=lastInstances .length ;}catch {}}}