假设我有3个扫描程序实例,我想关闭它.
我可以
sc.close()
Run Code Online (Sandbox Code Playgroud)
对于每个扫描仪.
或者我可以做类似的事情
for (Scanner sc: new Scanner[]{sc1,sc2,sc3}) {
sc.close();
}
Run Code Online (Sandbox Code Playgroud)
使用Java 8有没有更短的方法?
类似的东西?
{sc1,sc2,sc3}.forEach((sc) -> sc.close());
Run Code Online (Sandbox Code Playgroud) 我有一个android EditText,我正在设置文本属性.
通常我会用:
editText.text = "Mars"
Run Code Online (Sandbox Code Playgroud)
但是setter返回一个Editable,所以看起来Kotlin试图用失败的String替换返回的Editable.
所以"解决方法"是:
editText.setText("Mars")
Run Code Online (Sandbox Code Playgroud)
setText()当使用这种类型的setter时,有没有更漂亮的方法(而不是)设置文本?
如上所述, Oreo为每个应用程序提供了唯一的ANDROID_ID,这使得上一个命令无法按照我的意愿获取id.
adb shell settings get secure android_id
Run Code Online (Sandbox Code Playgroud)
我怎么能在Oreo上获得特定应用所看到的android id?
欢迎Root和非root解决方案.
组件 html 看起来有点像这样:
<form nz-form [formGroup]="form" (ngSubmit)="onSubmit()">
<button nz-button type="button" (click)="cancel()">
Cancel
</button>
<button nz-button type="submit" [nzType]="'primary'">
Submit
</button>
</form>
Run Code Online (Sandbox Code Playgroud)
组件类看起来有点像这样:
@Component({
selector: "my-form",
templateUrl: "./my-form.component.html",
styleUrls: ["./my-form.component.scss"]
})
export class MyFormComponent {
constructor(private fb: FormBuilder) {}
@Output()
onSuccess: EventEmitter<boolean> = new EventEmitter();
@Output()
onCancel = new EventEmitter<void>();
form: FormGroup = this.fb.group();
cancel() {
this.onCancel.emit();
}
onSubmit(): void {
if (formIsValid) {
this.onSuccess.emit(true);
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,事件发射器和事件处理程序应该如何命名?我可以遵守一些命名约定吗?
取消事件由该方法和事件发射器处理。cancel()onCancel
为什么是$args未定义的变量,它已经在回调之外定义了?我该如何解决这个问题?
我收到了错误 Undefined variable: args in ...
网址查询: products/category/1
$query = explode("/", $_SERVER['QUERY_STRING']);
$controller = (sizeof($query) >= 1 && !empty($query[0])) ? $query[0] : null;
$method = sizeof($query) >= 2 ? $query[1] : null;
$args = sizeof($query) >= 3 ? array_slice($query, 2, sizeof($query)) : null;
if(is_null($controller)) {
header("Location: ".URL . "?products/all");
}
if($controller === "products") {
$gw = new ProductDataGateway();
$products = null;
if($method === "all")
$products = $gw->getAllProducts();
elseif($method === "category" && sizeof($args) >= 1) {
$products = …Run Code Online (Sandbox Code Playgroud)