为什么会出现编译错误?
val autoClosable = MyAutoClosable()
var myVar: MyType
autoClosable.use {
myVar= it.foo()
}
println(myVar) // Error: Variable 'myVar' must be initialized
Run Code Online (Sandbox Code Playgroud)
也许编译器只是看作{ myVar= it.foo() }是一个传递给另一个函数的函数,并且不知道何时甚至是否会被执行?
但是,既然use不仅仅是一个函数,而且Kotlin取代了Java的资源尝试,那么关于它的一些特殊知识将是合适的,不是吗?现在,我被迫myVar用一些虚拟值初始化,这根本不符合Kotlin的精神.
我有三台主机,全部运行带有最新更新的 Ubuntu 18.04:
ansible --version产量:
ansible 2.9.6
config file = /home/marco/Desktop/playbook/ansible.cfg
configured module search path = [u'/home/marco/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Nov 7 2019, 10:07:09) [GCC 7.4.0]
Run Code Online (Sandbox Code Playgroud)
ansible.cfg包含行interpreter_python = auto.
我的剧本在与目标主机暂存一起运行时工作正常。但是当使用目标主机 prod 运行时,运行Expect模块时会失败:
An exception occurred during task execution. To see the full traceback, use -vvv. The …Run Code Online (Sandbox Code Playgroud) 量角器适用于Chrome,但我无法启动它来启动Firefox或Internet Explorer.
片段来自package.json:
"scripts": {
....
"webdriver-manager-update": "webdriver-manager update --ie",
"protractor": "protractor protractor.conf.js",
...
},
...
"devDependencies": {
...
"protractor": "5.1.1",
...
}
Run Code Online (Sandbox Code Playgroud)
protractor.conf.js:
exports.config = {
capabilities: {
browserName: "firefox" // or "internet explorer"
},
specs: ["target/e2e/**/*.e2e-spec.js"]
};
Run Code Online (Sandbox Code Playgroud)
运行后npm run webdriver-manager-update,<project-home>\node_modules\protractor\node_modules\webdriver-manager\selenium\包含文件chromedriver_2.28.exe,geckodriver-v0.15.0.exe和IEDriverServer3.3.0.exe.
运行时npm run protractor,我收到一个错误:
[12:29:45] I/launcher - Running 1 instances of WebDriver
[12:29:45] I/local - Starting selenium standalone server...
[12:29:46] I/local …Run Code Online (Sandbox Code Playgroud) 我对以下代码有问题。即使我指定了height: 100vh,body元素的高度 = 100vh +header元素的高度。我怎样才能解决这个问题?
body {
height: 100vh; /* It should never be necessary to scroll the whole page. */
margin: 0; /* Nothing should get added to the 100vh. */
}
header {
background-color: orange;
}
main {
display: flex;
height: 100%; /* Occupy all space that is not occupied by the header. */
}
.column-1 {
background-color: yellow;
width: 25%;
overflow-y: scroll; /* The only place where there should be a …Run Code Online (Sandbox Code Playgroud)当我使用Visual Studio构建(或重建)解决方案时,没有错误.但是,ReSharper的"解决方案中的错误"窗口显示错误,例如"无法解析符号","无法在此处访问私有方法"或"意外令牌".
两个文件受到影响.一个是.cs文件,另一个是.designer.cs文件.他们定义了同一个类partial.当我.designer.cs在Visual Studio编辑器中打开文件时,错误消失.
例如,十进制数0.1不能以任何有限精度的二进制浮点表示
但是,在C#中
string s = 0.1.ToString(CultureInfo.InvariantCulture);
Console.WriteLine(s);
Run Code Online (Sandbox Code Playgroud)
写道0.1.
我本以期待某事0.099999999999999999.
我正在寻找至少一个双精简版的例子,它不能完全代表双精度.
编辑:
正如其他人所指出的,0.1确实是我一直在寻找的文字,正如下面的经典代码示例所示:
double sum = 0.0;
for (int i = 0; i < 10; i++)
{
sum += 0.1;
}
Console.WriteLine(sum.Equals(1.0)); // false
Run Code Online (Sandbox Code Playgroud)
当双精度转换为其他数据类型时,会发生奇怪的事情.这不仅仅是string因为这个表达式是真的:0.1m.Equals((decimal)0.1)