On 22 October 2012 00:05, Reinier Zwitserloot <reini...@gmail.com> wrote:
> > > On Monday, October 15, 2012 2:55:49 PM UTC+2, Simon Ochsenreither wrote: >> >> >> One annoyance in Scala is when it infers a type to be, say, >>> List[Nothing], which so far has never been what I intended. >>> >> While I remember some “interesting” type inference results, List[Nothing] >> is a bad example. There is only one, single, unique value of List[Nothing] >> and it is the empty list. And in fact, that's the only possible element >> type of an empty list. >> >> > > That's false; a List[String] can happen to be empty. If you have a scala > method which accepts 1 List[String] as argument, you cannot presume that > this list will necessarily contain at least 1 element. > > It is very strange to have an _immutable_ empty List[String] but still > perfectly valid: If I need to call a method that takes a List[String], for > example for additional arguments to pass to an external process (think > j.l.ProcessBuilder), then I probably just want to use a nil list and pass > that in, at which point I'll have a List[String] reference that is pointing > at an immutable empty list. > > > That's kind of the point... A List[Nothing] *is* a List[String], or indeed a List[Anything you care for], on account of `Nothing` being a universal subtype. -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To post to this group, send email to javaposse@googlegroups.com. To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.