Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8113163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:44:24+00:00 2026-06-06T02:44:24+00:00

The code: object Link { //TYPE-1 (purely functional) def apply(name: String, target: Page, f:

  • 0

The code:

object Link {

  //TYPE-1 (purely functional)
  def apply(name: String, target: Page, f: () => Unit, isExclusive: Boolean) = new Link(name, target, f, isExclusive)
  //..

  //TYPE-2 (purely side-effect)
  def apply(source: Page, target: Page, f: () => Unit, isExclusive: Boolean): Link = {
    val link = Link("LINK [" + source.getName + "]->[" + target.getName + "]", target, f, isExclusive)
    source += link
    link
  }

  //type-2 too
  def apply(source: Page, target: Page, isExclusive: Boolean): Link = Link (source, target, () => Unit, isExclusive)

}

The explanation: there are two types of apply 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 second type-2 apply method where the _Link_ is marked with the underscores:

  def apply(source: Page, target: Page, isExclusive: Boolean): Link = _Link_ (source, target, () => Unit, isExclusive)

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 unless 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?

The error: the second apply method shows an error which reads:

overloaded method value apply with alternatives: (source:
org.app.Page,target:
org.app.Page,f: () => Unit,isExclusive:
Boolean)org.app.meta.Link < 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)

UPDATE

Please note that the type-1 apply method is called without problems from the first type-2 one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:44:26+00:00Added an answer on June 6, 2026 at 2:44 am

    This is not a bug, check the error message in detail (the interesting part is boldface below) and you will see that the last apply method actually passes a function of wrong type signature, () => Unit.type and not simply () => Unit.

    overloaded method value apply with alternatives: (source: org.app.Page,target: org.app.Page,f: () => Unit,isExclusive: Boolean)org.app.meta.Link < 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)

    The reason is that there is only one value of type Unit, namely (), in your case however, when you call () => Unit in the last apply method, you are returning the companion object of type Unit and not its value.

    To fix the error your getting, simply replace () => Unit with () => () in your last apply method.

    It should then look like this:

    def apply(source: Page, target: Page, isExclusive: Boolean): Link = Link (source, target, () => (), isExclusive)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This link shows how to inject JavaScript code to WebView object in Android. However
Dummy code: public object Addition(object a, object b) { var type = a.GetType(); var
I am receiving an error on the following line of code: Object reference not
I have the following code (changed object names, so syntax/spelling errors ignore). public class
I'm inside a shared object (code) loaded with dlopen. I want to know the
I have a list of a object Code: List<Code> listCodes = new List<Code>(); I
using jquery's .post i send do my php code an object that with var_dump
What is the difference between the following two snippets of code: using (Object o
I am writing code to clone object but have no cue from Hobo documentation.
I am using the below code protected void lnk_Click(object sender, EventArgs e) { try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.