Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is one of the reasons existential types (the Scala equivalent of wildcard types) are a Bad Thing (TM) that is best avoided when not doing Java interop: the compiler cannot (or just isn't smart enough to) reason normally about which types are equal to which, because they are all gone... </p> <p>To make the compiler understand that those types are the same, you need to give that type a name somehow. </p> <p>A type parameter is a possibility: you define a parametrized method with the content of your for comprehension, so that within the method, the type is well-known.</p> <pre><code>def callHandler(url: String) { def call[T](r: Route[T]) = { val args = r.matcher.matchUrl(url) if (args.isDefined) r.handler(args.get) // or args.foreach(r.handler) } for (r &lt;- routes) call(r) // or routes.foreach(call) } </code></pre> <p><em>Note</em>: in simpler cases, you could also use variance to have a <code>List[Route[Any]]</code>, and your problem goes away, the type is well-known again. Here I am not sure you could make <code>Route[A]</code> covariant.</p> <p><a href="https://stackoverflow.com/questions/1031042/scalas-existential-types">Existential types</a> mostly exist to represent Java wildcards, Java raw types and the JVM's view of types (reflection and stuff), even though <strong>they are more powerful than those three constructs</strong>. <strike>If you can design things to avoid using them, you will save yourself a lot of pain.</strike> This was a bit controversial, but a least, there are a lot of limitations with the way they interact with type inference, so one has to be careful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload