这是eval在Dart平台中使用此方法的代码.
这是通过反射完成的.
_getFieldSlow(unwrapped) {
// ..... Skipped
var atPosition = unwrapped.indexOf('@');
if (atPosition == -1) {
// Public symbol.
f = _eval('(x) => x.$unwrapped', null);
} else {
// Private symbol.
var withoutKey = unwrapped.substring(0, atPosition);
var privateKey = unwrapped.substring(atPosition);
f = _eval('(x) => x.$withoutKey', privateKey);
}
// ..... Skipped
}
Run Code Online (Sandbox Code Playgroud)
static _eval(expression, privateKey)
native "Mirrors_evalInLibraryWithPrivateKey";
Run Code Online (Sandbox Code Playgroud)
DEFINE_NATIVE_ENTRY(Mirrors_evalInLibraryWithPrivateKey, 2) {
GET_NON_NULL_NATIVE_ARGUMENT(String, expression, arguments->NativeArgAt(0));
GET_NATIVE_ARGUMENT(String, private_key, arguments->NativeArgAt(1));
const GrowableObjectArray& libraries =
GrowableObjectArray::Handle(isolate->object_store()->libraries());
const int num_libraries = …Run Code Online (Sandbox Code Playgroud) 我可以在 Dart SDK 的哪里找到 的实现UnmodifiableSetView?
在C#语言中存在System.Collections.Immutable.ImmutableHashSet<T>.
在Java语言中存在Collections.unmodifiableSet()。
但我在 Dart SDK 中找不到类似的东西。
在 Dart SDK 中哪里可以找到它?
聚苯乙烯
我使用 Dart 语言不是为了将其编译为 Javascript 语言。
我使用它(按原样)进行计算,并且我需要UnmodifiableSetView它,但我在 Dart SDK 中找不到它。
在C#langauge中存在用于此目的的全局系统变量.
Environment.CommandLine
Run Code Online (Sandbox Code Playgroud)
此属性提供对当前进程启动时程序名称和命令行上指定的任何参数的访问.
Dart是异步语言.它允许自启动过程.
void main() {
task("foo", callback1);
task("baz", callback2);
}
Run Code Online (Sandbox Code Playgroud)
包装任务.
void task(String name, action()) {
schedule();
addTask(name. action);
}
void schedule() {
// Here we start timer if it not started.
// This timer will get cmd line arguments
// And executes task specified in cmd line arguments
}
Run Code Online (Sandbox Code Playgroud)
PS
Dart团队的官方回答:"没有计划".
我无法理解:"为什么在其他平台上通过他们的库可以实现这一点,但在Dart平台上这是不可能的?".
为什么只通过"主要"参数甚至不能确保其他隔离不会在代理参数上替换这些参数而不是真正的OS进程命令行参数?
这里的例子:
func main() {
fmt.Println(len(os.Args), os.Args)
}
Run Code Online (Sandbox Code Playgroud)
fn main() {
let args = os::args();
println!("The first argument is {}", args[1]);
}
Run Code Online (Sandbox Code Playgroud)
Dart编辑器版本1.2.0.release(STABLE).Dart SDK 1.2.0版.
此源代码生成运行时异常.
void main() {
test(new Base());
}
void test(Child child) {
}
class Base {
}
class Child extends Base {
}
Run Code Online (Sandbox Code Playgroud)
我假设分析仪生成这样的东西.
The argument type 'Base' cannot be assigned to the parameter type 'Child'
Run Code Online (Sandbox Code Playgroud)
但是我只能在发生此异常(post factum)时在运行时检测到此错误.
Unhandled exception:
type 'Base' is not a subtype of type 'Child' of 'child'.
Run Code Online (Sandbox Code Playgroud) code-analysis software-quality error-detection dart dart-sdk
我无法理解为什么Dart风格指南写的?
PREFER本指南的术语:
"PREFER指南是您应该遵循的做法.但是,在某些情况下可能会有其他意义.只要确保您了解在执行此操作时忽略指南的全部含义"
现在是经常讨论的主要做法之一,当然,我们应该遵循它:
简而言之,不建议在函数体中使用类型注释(除了一些非常具体的情况).
但是当我查看Dart SDK的源代码时,我经常会看到相反的情况.
只是来自许多其他类似的一个样本.
例:
void operator []=(K key, V value) {
int hashCode = key.hashCode;
List buckets = _buckets;
int length = buckets.length;
int index = hashCode & (length - 1);
_HashMapEntry entry = buckets[index];
while(entry != null) {
if (hashCode == entry.hashCode && entry.key == key) {
entry.value = value;
return;
}
entry = entry.next;
}
_addEntry(buckets, index, length, key, value, hashCode);
}
Run Code Online (Sandbox Code Playgroud)
为什么Dart团队使用类型注释代替局部变量var?