dartdocsInstanceMirror.type
님reflectClass (o.runtimeType)이 reflect (o) .type과 다른 결과를 반환하는 상황은 무엇입니까? 발
"는 reflectee 실제 클래스에 거울을 반환 reflectee의 클래스는 reflectee RuntimeType이 호출에 의해 리턴 된 객체와 다를 수있다.."
따라서 어떤 상황에서 reflectClass(o.runtimeType)
은 reflect(o).type
과 다른 결과를 반환합니까?
나는 예제 코드로 시도 :
import 'dart:mirrors';
class A{}
void main() {
var string = "str";
var boolean = true;
var integer = 5;
var map = {};
var list = [];
var custom = new A();
var strRunT = string.runtimeType;
var strRefT = reflect(string).type.reflectedType;
var boolRunT = boolean.runtimeType;
var boolRefT = reflect(boolean).type.reflectedType;
var intRunT = integer.runtimeType;
var intRefT = reflect(integer).type.reflectedType;
var mapRunT = map.runtimeType;
var mapRefT = reflect(map).type.reflectedType;
var listRunT = list.runtimeType;
var listRefT = reflect(list).type.reflectedType;
var cusRunT = custom.runtimeType;
var cusRefT = reflect(custom).type.reflectedType;
print('string');
print('runtimeType = $strRunT');
print('reflectedType = $strRefT');
print('runT == refT = ${strRunT == strRefT}');
print('runT == String = ${strRunT == String}');
print('refT == String = ${strRefT == String}');
print('');
print('bool');
print('runtimeType = $boolRunT');
print('reflectedType = $boolRefT');
print('runT == refT = ${boolRunT == boolRefT}');
print('runT == bool = ${boolRunT == bool}');
print('refT == bool = ${boolRefT == bool}');
print('');
print('integer');
print('runtimeType = $intRunT');
print('reflectedType = $intRefT');
print('runT == refT = ${intRunT == intRefT}');
print('runT == int = ${intRunT == int}');
print('refT == int = ${intRefT == int}');
print('');
print('map');
print('runtimeType = $mapRunT');
print('reflectedType = $mapRefT');
print('runT == refT = ${mapRunT == mapRefT}');
print('runT == Map = ${mapRunT == Map}');
print('refT == Map = ${mapRefT == Map}');
print('');
print('list');
print('runtimeType = $listRunT');
print('reflectedType = $listRefT');
print('runT == refT = ${listRunT == listRefT}');
print('runT == List = ${listRunT == List}');
print('refT == List = ${listRefT == List}');
print('');
print('custom');
print('runtimeType = $cusRunT');
print('reflectedType = $cusRefT');
print('runT == refT = ${cusRunT == cusRefT}');
print('runT == A = ${cusRunT == A}');
print('refT == A = ${cusRefT == A}');
print('');
}
//OUTPUT
string
runtimeType = String
reflectedType = String
runT == refT = false
runT == String = true
refT == String = false
bool
runtimeType = bool
reflectedType = bool
runT == refT = true
runT == bool = true
refT == bool = true
integer
runtimeType = int
reflectedType = int
runT == refT = false
runT == int = true
refT == int = false
map
runtimeType = _LinkedHashMap
reflectedType = _LinkedHashMap
runT == refT = true
runT == Map = false
refT == Map = false
list
runtimeType = List
reflectedType = List
runT == refT = true
runT == List = false
refT == List = false
custom
runtimeType = A
reflectedType = A
runT == refT = true
runT == A = true
refT == A = true
추가 어쨌든 2 개 Type
들 비교가 동일한 경우 찾는가? 위의 예 에서처럼 int
의 두 가지 유형이 일반 ==
연산자를 사용하여 동일하지 않음을 보여줍니다.