为什么这个匿名函数以println开头会导致NullPointerException? [英] Why does this anonymous function starting with println result in a NullPointerException?
本文介绍了为什么这个匿名函数以println开头会导致NullPointerException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在了解 pmap
并撰写了以下函数:
(pmap#((printlnhello from( - >(Thread / currentThread).getName))
(+%1%2))
[-1 1 1] [-1 -1 -1])$ b $ b
运行时,结果是 NullPointerException
(来自clojure-agent-send-off-pool-4
hello from clojure- agent-send-off-pool-3
hello从clojure-agent-send-off-pool-5
NullPointerException用户/ eval55 / fn - 56(NO_SOURCE_FILE:11)
为什么会发生这种情况?我理解并观察了 fn
为 do
解决方案
匿名 fn
literal #()
没有隐式 do
p>
I am learning about pmap
and wrote the following function:
(pmap #((println "hello from " (-> (Thread/currentThread) .getName))
(+ %1 %2))
[1 1 1] [-1 -1 -1])
When run, the result is a NullPointerException
(hello from clojure-agent-send-off-pool-4
hello from clojure-agent-send-off-pool-3
hello from clojure-agent-send-off-pool-5
NullPointerException user/eval55/fn--56 (NO_SOURCE_FILE:11)
Why is this happening? I have understood and observed the body of a fn
to be an implicit do
.
解决方案
The anonymous fn
literal #()
does not have an implicit do
.
这篇关于为什么这个匿名函数以println开头会导致NullPointerException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文