Reputation: 25
I have confused about the code below. Why this can run? And what is the meaning of the .isEmpty
. In the process of calling test
, and I am mysterious about the {
means what? A new Function?
def test(age:Int)(name:name_class => name_class): String = {
val str: String = name.toString()+age+""
print(str)
str
}
test(19){
x =>
name_class("dage1")
}.isEmpty
Upvotes: 0
Views: 66
Reputation: 51271
def test
- test
is a method.(age:Int)
- It takes an Int
parameter. We'll call it age
.(name:name_class => name_class)
- It takes a 2nd parameter (curried) that is a function that takes a name_class
and returns a name_class
. We'll call that function name
.: String
- Method test
returns a String
....
test(19)
- Let's invoke the test
method. The 1st argument, age
, will be 19.{
- The 2nd argument to test
starts here. It might be multiple lines of code so we'll use {...}
instead of (...)
. (Actually not needed in this case.)x=>
- This is a function that takes a name_class
. We'll call it x
. (And ignore it hereafter.)name_class("dage1")
- Return a name_class
.}
- All done with the 2nd argument to test
..isEmpty
- Test the String
that test
returns to see if it is empty.Upvotes: 3