With SAM types, we can have:
trait Sam {
def foo(i: Int): String
}
val sam : Sam = _.toString
What if my abstract method doesn't have a parameter?
With SAM types, we can have:
trait Sam {
def foo(i: Int): String
}
val sam : Sam = _.toString
What if my abstract method doesn't have a parameter?
Copyright © 2021 Jogjafile Inc.
You can use a lambda with an empty argument list like this:
You can not use
_notation because there's no way to define a zero-argument function with_.This won't work if
foois defined asdef foo: Stringinstead (i.e. if it doesn't have a parameter list) because SAM-conversion only applies if the single method has exactly one parameter list.