我有List中categories和他们的products,我想执行这些操作:
如何在Dart中完成这项工作?
void main() {
var books = new Category(0, "Books");
var magazines = new Category(1, "Magazines");
var categories = [books, magazines];
var products = [
new Product(0, "Dr. Dobb's", magazines),
new Product(1, "PC Magazine", magazines),
new Product(2, "Macworld", magazines),
new Product(3, "Introduction To Expert Systems", books),
new Product(4, "Compilers: Principles, Techniques, and Tools", books),
];
// How to map product list by id?
// How to group product …Run Code Online (Sandbox Code Playgroud) 我无法理解:"为什么要这样保证?"
这是自定义本机函数的包装dart/runtime/vm/native_entry.cc:
它适用于想要写入的Dart程序员native extensions.
void NativeEntry::NativeCallWrapper(Dart_NativeArguments args,
Dart_NativeFunction func) {
CHECK_STACK_ALIGNMENT;
VERIFY_ON_TRANSITION;
NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
Isolate* isolate = arguments->isolate();
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
ApiLocalScope* current_top_scope = state->top_scope();
ApiLocalScope* scope = state->reusable_scope();
TRACE_NATIVE_CALL("0x%" Px "", reinterpret_cast<uintptr_t>(func));
if (scope == NULL) {
scope = new ApiLocalScope(current_top_scope,
isolate->top_exit_frame_info());
ASSERT(scope != NULL);
} else {
scope->Reinit(isolate,
current_top_scope,
isolate->top_exit_frame_info());
state->set_reusable_scope(NULL);
}
state->set_top_scope(scope); // New scope is now the top scope.
func(args);
ASSERT(current_top_scope == scope->previous());
state->set_top_scope(current_top_scope); // Reset …Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
struct s {int;};
int main()
{
printf("Size of 'struct s': %i\n", sizeof(struct s));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Microsoft C编译器(cl.exe)不希望编译此代码.
error C2208: 'int' : no members defined using this type
Run Code Online (Sandbox Code Playgroud)
GNU C编译器(gcc -std = c99)编译此代码...
warning: declaration does not declare anything
Run Code Online (Sandbox Code Playgroud)
...并显示结果:
Size of 'struct s': 0
Run Code Online (Sandbox Code Playgroud)
这意味着struct s在gcc中是完整类型而无法重新定义.
这是否意味着完整类型的大小可以为零?
此外,declaration does not declare anything如果此声明声明完整的结构,该消息是什么意思?
以下是struct s(gcc -std = c99)中完整类型的证明.
#include <stdio.h>
struct s {int;};
struct S {
struct s s; // <=========== No …Run Code Online (Sandbox Code Playgroud) 关于"native"子句,我在语言规范中找不到任何内容.谁能解释我这定义为语言的一部分?
用Dart语言编写的代码示例:
double get defaultValue native "AudioParam_defaultValue_Getter";
Run Code Online (Sandbox Code Playgroud)
我知道这是为了将包装器写入本机代码,但我找不到这个定义它是一个有效的语言元素.
我无法理解NullDart中的内容.
在C#语言中null是一个文字.这null是reference-type变量的默认值.
在nullC#中没有类型.无法null通过点访问成员..
例:
String s = null; // the default value of reference-type variable
null.GetType(); // Operator '.' cannot be applied to operand of the type <null>
Run Code Online (Sandbox Code Playgroud)
在Dart中null有一种类型Null.但是NullDart中的bottom类型实例不是一种类型.
根据类型继承,这在Dart中是如何工作的?
// How the `null` value with type of `Null`
// can be assigned to a `String` type?
String s = null;
Run Code Online (Sandbox Code Playgroud)
此代码在Dart编辑器中产生奇怪的警告.
"Tests for null should be done with '== …Run Code Online (Sandbox Code Playgroud) 在 Dart 中存在两种类型。
这是Dart 语言规范中的证明:
null的静态类型是底部。
null是Null null是bottom这意味着 Dart 中的对象可以有两种类型。
一种调用的真实类型static和一种virtual调用的类型runtime。
也就是说,运行时类型null不是 abottom而是一个普通的 class Null。
class Null {
factory Null._uninstantiable() {
throw new UnsupportedError('class Null cannot be instantiated');
}
/** Returns the string `"null"`. */
String toString() => "null";
}
Run Code Online (Sandbox Code Playgroud)
但是同时具有这个常规运行时类型的Null值可以分配给任何其他类型,因为 的真实(静态)类型null是一种bottom类型。
在 Dart 中如何称呼这种技术?
类型替换或不同的东西?
聚苯乙烯
这个问题是关于值的静态类型,而不是关于使用类型注释声明的变量的静态类型。 …
如何从 Future 对象返回 Future 值?这段代码不起作用。
import 'dart:async';
void main() {
var temp = foo();
temp.then((Future<int> future) {
future.then((int result) {
print(result);
});
});
}
Future<Future<int>> foo() {
return new Future<Future<int>>(() {
return new Future<int>(() => 5);
});
}
Run Code Online (Sandbox Code Playgroud)
如何避免不必要的拆包?
在这种情况下,在异步库“Future”中声明为通用类。
abstract class Future<T> {
}
Run Code Online (Sandbox Code Playgroud)
如果我创建如下表达式
new Future<Future<int>>();
Run Code Online (Sandbox Code Playgroud)
然后将类型T 指定为Future<int>泛型类 Future 预期的结果?
我认为结果必须与 type argument 中指定的相同T。
IEFuture<int>.
但结果并不如预期。在 Dart API 网站上没有找到有关此异常行为的信息。
如果这是一个“功能”(但我认为异常行为错误地称为“功能”)那么为什么它没有记录在 Dart API 中?
如何解释这种差异?
为什么这段代码没有生成错误和警告?
另一个相同的例子,但没有使用 Future。
void main() {
var temp …Run Code Online (Sandbox Code Playgroud) 我正在学习飞镖.当我写下一个代码时:
class Hero
{
String name;
Hero(this.name);
}
class AppComponent
{
String title = 'header';
Hero hero = 'Windstorm';
}
Hero hero = new Hero('test');
Run Code Online (Sandbox Code Playgroud)
我收到了错误:
A value of type 'String' cannot be assigned to a variable of type 'Hero'.
我做错了什么?
这是 Dart 语言的示例:
patch class List<E> {
}
Run Code Online (Sandbox Code Playgroud)
这不是补丁文件,因为它具有扩展名.dart并且包含用 Dart 语言编写的常规源代码(关键字除外)patch。
该关键字将来会在TC52-Dart-Ecma International中标准化吗?
This script (source code) can be perfectly executed in the production mode.
void main() {
int greeting = "Hello world!";
print(greeting);
}
Run Code Online (Sandbox Code Playgroud)
This is a traditional hello world example that works fine in Dart.
The result is "Hello world!".
This script is self enough because not required other functionality and it works as expected.
Now I have small questions:
dart ×9
angular-dart ×1
bottom-type ×1
c ×1
c# ×1
c++ ×1
c99 ×1
dart-async ×1
dart-sdk ×1
gcc ×1
keyword ×1
native-code ×1
null ×1
oop ×1
performance ×1
scala ×1
struct ×1
type-systems ×1
visual-c++ ×1