[英]I can't pass the argument while using higher order function
Here you can see that I can't pass that string parameter在这里你可以看到我不能传递那个字符串参数
I somehow learned how to pass a method in the same class but, when I want to call it from another class, I can't pass the arguments.我不知何故学会了如何在同一个类中传递一个方法,但是当我想从另一个类调用它时,我无法传递参数。
Several issues here:这里有几个问题:
introduceMyself
method accepts a higher-order function, but in its usage it seems that you don't want the method itself, but its result. introduceMyself
方法接受一个高阶函数,但在它的使用中,您似乎不想要方法本身,而是它的结果。 I'd suggest replacing the getName
parameter with name
parameter and convert it to a regular string which will be provided externally by an invocation of said method.getName
参数替换为name
参数并将其转换为常规字符串,该字符串将通过调用所述方法在外部提供。person
, you can replace the :: with a .person
,因此您可以将 :: 替换为 . like so: person.myNameIs("michael")
.person.myNameIs("michael")
。 It's not working because :: passes the method itself, which you don't really want. Finally, you can pass higher order functions, but you can't pass them "with an argument".最后,您可以传递高阶函数,但不能“带参数”传递它们。 You can do one of 3 things:
您可以做以下三件事之一:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.