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. 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.person
, you can replace the :: with a . like so: person.myNameIs("michael")
. It's not working because :: passes the method itself, which you don't really want. Again, your code implies that you need to pass the result of the method and not the method itself.Finally, you can pass higher order functions, but you can't pass them "with an argument". You can do one of 3 things:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.