Reputation: 344
I am currently in a project where I need to learn Scala and Lift, so I am reading Beginning Scala atm. Everything went fine until I reached the method declaration, in which it has these confusing line of code
def list[T](p : T): List[T] = p::nil
list:[T](T)List[T]
Author wrote that this is pretty obvious, but... help?
Upvotes: 0
Views: 69
Reputation: 3887
The first line def list[T](p : T): List[T] = p::Nil
defines a method named list
which takes a argument of type parameter T
and returns an output of type List[T]
by creating a list using p::Nil
.
The second line list:[T](p:T)List[T]
shows the method signature, which again implies the same.
If you try def list[T](p : T): List[T] = p::Nil
in scala repl you get list:[T](p:T)List[T]
.
Upvotes: 3