我在PowerShell中使用Ack版本2.04.我想在文本文件中搜索像"jsonClass"这样的文本:"Page"(包括引号).
我似乎无法得到引用和逃避正确.
ack -c --match '"jsonClass":"Page"'
Run Code Online (Sandbox Code Playgroud)
它在PowerShell中不起作用.我猜ack也拿起单引号.
转义双引号会产生无效的正则表达式错误:
ack -c --match "\"jsonClass\":\"Page\""
Invalid regex '\':
Trailing \ in regex m/\/ at C:\CHOCOL~1\lib\ACK2~1.04\content\ack.pl line 315
Run Code Online (Sandbox Code Playgroud)
我也尝试了文字选项,但我认为ack将冒号解释为文件参数.
ack -c -Q --match "jsonClass":"Page"
ack.pl: :Page: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我正在使用PowerShell v2.
我想向 ExecutorService 提交一个 lambda。lambda 正在关闭一个累积的 Arraylist,但我使用“toArray”传递了一个防御性副本,然后清除了累加器。似乎 lambda 没有捕获“toArray”的响应。
但是,如果我将副本分配给 lambda 之外的另一个引用,那么它会得到正确处理。
原始代码:
public class Test {
public static void main(String[] args) {
final int BATCH = 10;
ArrayList<Integer> accumulator = new ArrayList<>();
ExecutorService executorService = Executors.newFixedThreadPool(3);
for (int i = 0; i < BATCH * 10; i++) {
accumulator.add(i);
if (accumulator.size() >= BATCH) {
executorService.submit(() -> run(accumulator.toArray())); // faulty
accumulator.clear();
}
}
executorService.shutdown();
try {
if (!executorService.awaitTermination(10, TimeUnit.MINUTES)) {
System.err.println("Waited for 10 minutes, forced exit");
System.exit(0);
}
} catch (InterruptedException …Run Code Online (Sandbox Code Playgroud) 是否可以编写一个泛型函数,该函数接受“Any”类型的值和泛型类型参数说“T”并通过检查传入值的运行时类型返回 Option[T] ?
我尝试了 repl (Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_66))
def cast[T](x: Any): Option[T] = x match {
case v: T => Some(v)
case _ => Option.empty[T]
}
Run Code Online (Sandbox Code Playgroud)
我收到警告:
warning: abstract type pattern T is unchecked since it is eliminated by erasure
case v: T => Some(v)
Run Code Online (Sandbox Code Playgroud)
我如何传递类类型并进行显式类型检查而不是泛型?
PS显然由于类型擦除上述代码爆炸。示例 repl 交互:
scala> val x :Any = 123
x: Any = 123
scala> cast[Int](x)
res0: Option[Int] = Some(123)
scala> cast[String](x)
res1: Option[String] = Some(123)
scala> val …Run Code Online (Sandbox Code Playgroud)