像这样写这里会报错
final AtomicLong subtotal = new AtomicLong(limit);
final long maxPrimeFactor = primeStream.takeWhile(p -> p * p <= limit)
.filter(p -> subtotal.get() % p == 0)
.peek(p -> while((subtotal.get() % p == 0) && (subtotal.get() > p)) subtotal.set(subtotal.get() / p)) // Syntax error here.
.dropWhile(p -> p != subtotal.get())
.findFirst()
.getAsLong();
如果换成这样就没问题
final AtomicLong subtotal = new AtomicLong(limit);
final long maxPrimeFactor = primeStream.takeWhile(p -> p * p <= limit)
.filter(p -> subtotal.get() % p == 0)
.peek(p -> { while((subtotal.get() % p == 0) && (subtotal.get() > p)) subtotal.set(subtotal.get() / p)); } // No syntax error here.
.dropWhile(p -> p != subtotal.get())
.findFirst()
.getAsLong();
p->xx 这里xx是表达,而不是陈述。
p->{xx}这里xx是语句,或者准确地说,是语句块。