我想重命名一个在角度模板文件(即xxx.component.html文件)中使用的变量。这可以通过WebStorm 中的Shift+F6快捷方式来完成。如何在 vscode 中做到这一点?F2没有帮助。
下面的代码记录赋值a后的值
var a = []
if (true) {
a = 1
function a() {}
a = 2
function a() {}
a = 3
console.log('0: ', a)
}
console.log('1: ', a)Run Code Online (Sandbox Code Playgroud)
我怀疑输出可能是:
0: 3
1: 3
Run Code Online (Sandbox Code Playgroud)
但实际上上面的代码记录了
0: 3
1: 2
Run Code Online (Sandbox Code Playgroud)
为什么?
import java.util.HashMap;\nimport java.util.HashSet;\n\npublic class ComputeIfAbsentWithHashSetNew {\n public static void main(String[] args) {\n var map = new HashMap<Integer, HashSet<Integer>>();\n var data = new int[][]{{305589003, 4136}, {305589004, 4139}};\n for (var entry : data) {\n int x = entry[0];\n int y = entry[1];\n// map.computeIfAbsent(x, _x -> new HashSet<>()).add(y); // ----- line 1\n var k = map.computeIfAbsent(x, HashSet::new); // ----- line 2\n k.add(y);\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n上面的代码抛出 jdk 17\xe3\x80\x81 18\xe3\x80\x81 19:
\nException in thread "main" java.lang.OutOfMemoryError: Java heap space\n at java.base/java.util.HashMap.resize(HashMap.java:702)\n at java.base/java.util.HashMap.putVal(HashMap.java:627)\n …Run Code Online (Sandbox Code Playgroud) 我想为变量p分配引用:
Function<?, Void> p = System.out::println; // [1]
Run Code Online (Sandbox Code Playgroud)
所以我可以像以下一样使用它:
p("Hello world"); // I wish `p` to behave exactly same as `System.out.println`
Run Code Online (Sandbox Code Playgroud)
表达式[1]产生编译错误,如何解决?
线程"main"中的异常java.lang.Error:未解决的编译问题:
PrintStream类型的println(Object)类型为void,这与描述符的返回类型不兼容:Void
如果变Void到void错误变为:
线程"main"中的异常java.lang.Error:未解决的编译问题:语法错误,插入"Dimensions"以完成ReferenceType
如果有足够的时间,这个循环会完成吗?
for (let i = 0; 1 / i > 0; i++) {} // js code [0]
Run Code Online (Sandbox Code Playgroud)
我想它会i到达Number.POSITIVE_INFINITY但不知道如何测试.
编辑:
for (let i = 0; 1 / i > 0; i += k) {} // js code [1]
Run Code Online (Sandbox Code Playgroud)
k使js代码[1]完成的最小正数是多少?(至少k = 1e304会)
让我们假设答案是问题1 K,是否有任何数字大于K保证js代码完成[1]?
更新:Integer[][]用作 src 数组类型可以使以下代码工作。
我想转换int[][]为List<List<Integer>>并尝试使用:
int[][] arr = new int[][]{{2}, {3, 4}, {6, 5, 7}, {4, 1, 8, 3}};
List<List<Integer>> ll = Arrays.stream(arr)
.map(Arrays::asList) // I expect this produces Stream<List<Integer>> but it was actually a Stream<List<int[]>>.
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
编译器发出错误:
| Error:
| incompatible types: inference variable T has incompatible bounds
| equality constraints: java.util.List<java.lang.Integer>
| lower bounds: java.util.List<int[]>
| List<List<Integer>> ll = Arrays.stream(arr).map(Arrays::asList).collect(Collectors.toList());
| ^-----------------------------------------------------------------^
Run Code Online (Sandbox Code Playgroud)