Note that there are some explanatory texts on larger screens.

plurals
  1. POScala-IDE - object `apply` methods with different signatures get mixed?
    text
    copied!<p>The code:</p> <pre><code>object Link { //TYPE-1 (purely functional) def apply(name: String, target: Page, f: () =&gt; Unit, isExclusive: Boolean) = new Link(name, target, f, isExclusive) //.. //TYPE-2 (purely side-effect) def apply(source: Page, target: Page, f: () =&gt; Unit, isExclusive: Boolean): Link = { val link = Link("LINK [" + source.getName + "]-&gt;[" + target.getName + "]", target, f, isExclusive) source += link link } //type-2 too def apply(source: Page, target: Page, isExclusive: Boolean): Link = Link (source, target, () =&gt; Unit, isExclusive) } </code></pre> <p>The explanation: there are two types of <code>apply</code> methods - the type-1 simply returns what companion class constructor returns, and the type-2 does not return anything, instead it just does something with the new instance. Thus the two different sets of arguments for them. However, I get the error (see the bottom of the post) on the <em>second</em> type-2 apply method where the <code>_Link_</code> is marked with the underscores:</p> <pre><code> def apply(source: Page, target: Page, isExclusive: Boolean): Link = _Link_ (source, target, () =&gt; Unit, isExclusive) </code></pre> <p>The first type-2 apply method does some job and in the second (and 3rd and 4th...) type-2 apply methods I want to just refer to the first one, instead of duplicating what is written there. However, Scala-IDE does not allow me to do this <em>unless</em> all the apply methods of type-1 are commented out. Seems like that Scala-IDE gets lost among the signatures and can't see my obvious intent. Or am I doing something wrong?</p> <p>The error: the second <code>apply</code> method shows an error which reads:</p> <blockquote> <p>overloaded method value apply with alternatives: (source: org.app.Page,target: org.app.Page,f: () => Unit,isExclusive: Boolean)org.app.meta.Link &lt; and> (name: String,target: org.app.Page,f: () => Unit,isExclusive: Boolean)org.app.meta.Link cannot be applied to (org.app.Page, org.app.Page, () => Unit.type, Boolean)</p> </blockquote> <p><strong>UPDATE</strong></p> <p>Please note that the type-1 apply method is called without problems from the first type-2 one.</p>
 

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