scala-user@googlegroups.com
Discussion:
Seq.empty[T] vs. Nil?
Willis Blackburn
2010-09-30 11:07:59 UTC
Permalink
Does anyone use Seq.empty[T]? Nil always seems to fit the bill and is shorter.
W
Stefan Langer
2010-09-30 12:55:31 UTC
Permalink
Sometimes you need to add a type to your Seq or List for the Inferer
and in this case
Nil doesn't cut it as it always uses Nothing as the type.
Stefan
Does anyone use Seq.empty[T]? Nil always seems to fit the bill and is shorter.
W
Germán Ferrari
2010-09-30 12:57:30 UTC
Permalink
Hi,
I prefer
var ns = Seq.empty[Int]
to
var ns: Seq[Int] = Nil
The type hint is required in the second case so the compiler don't infer
"List[Nothing]" (from which "Nil" extends).
Regards,
Germán
Post by Willis Blackburn
Does anyone use Seq.empty[T]? Nil always seems to fit the bill and is shorter.
W
2 Replies
822 Views
Permalink to this page
Disable enhanced parsing
Thread Navigation
Willis Blackburn
2010-09-30 11:07:59 UTC
Stefan Langer
2010-09-30 12:55:31 UTC
Germán Ferrari
2010-09-30 12:57:30 UTC
Loading...