class ImmutablePoint {
final int x;
final int y;
const ImmutablePoint(this.x, this.y);
}
void main() {
var a = const ImmutablePoint(1, 1);
print('The type of a is ${a.runtimeType}');
}
runtimeType 속성 대신 타입 테스트 연산자를 이용해 객체의 유형을 검사하세요. 프로덕션 환경에서 object is Type 검사 object.runtimeType == Type 검사보다 더 안정적입니다.
class ImmutablePoint {
final int x;
final int y;
const ImmutablePoint(this.x, this.y);
}
void main() {
var a = ImmutablePoint(1, 1);
print('a is ImmutablePoint? ${a is ImmutablePoint}');
dynamic b = ImmutablePoint(2, 3);
if (b is ImmutablePoint) {
print('b.x=${(b as ImmutablePoint).x}, b.y=${(b as ImmutablePoint).y}');
}
}