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

  • Home
  • SEARCH
  • 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 6113263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:50:19+00:00 2026-05-23T14:50:19+00:00

Isn’t toList a method that converts something into a List? If yes so why

  • 0

Isn’t toList a method that converts something into a List?

If yes so why can’t I use parenthesis with it? I must be missing something more fundamental here.

Here is the example:

val l = Array(1,2,3).toList // works fine

val l = Array(1,2,3).toList() // gives the error below

Not enough arguments for method apply: (n: Int)Int in trait
LinearSeqOptimized. Unspecified value parameter n.

  • 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-05-23T14:50:20+00:00Added an answer on May 23, 2026 at 2:50 pm

    If a method is defined as

    def toList = { /* something */ }
    

    then it must be called as

    object.toList
    

    with no extra parentheses. We say that this method has zero parameter lists.

    We could also define a parameter list but put nothing in it:

    def toList() = { /* something */ }
    

    Now, we could call either of

    object.toList()
    object.toList
    

    since Scala allows the shortcut of omitting parentheses on method calls.

    As far as the JVM is concerned, there is no difference between the first definition (“zero parameter lists”) and the second (“one empty parameter list”). But Scala maintains a distinction. Whether this is a good idea or not is debatable, but the motivation might be clearer when you realize that we can also

    def toList()() = { /* something */ }
    

    which is known as two empty parameter lists, and then call any of

    object.toList()()
    object.toList()
    object.toList
    

    and now, if we were to convert this into a function, we would type it as

    () => () => T   /* T is the return value of the something */
    

    while the second definition would be

    () => T
    

    which is clearly different conceptually, even if practically you use it the same way (put in nothing and sooner or later get out a T).

    Anyway, toList doesn’t need any parameters, and the Scala standard is to leave off the parens unless the method changes the object itself (rather than just returning something), so it’s def toList without any parens afterwards. And thus you can only call it as object.toList.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why isn't there a logout button? Why no list of websites you're logged into?
Isn't the use of delegates to help with some asynchronous cases? I tried the
I have a French site that I want to parse, but am running into
Isn't that an inconsistent behavior? (PHP 5.2.6) <?php $a = new SimpleXMLElement('<a/>'); $a->addAttribute('b', 'One
Isn't there a way with Hibernate to return a list of (primitive) values from
Isn't that nicely recursive? I've got a portable command prompt on my external drive,
This isn't legal: public class MyBaseClass { public MyBaseClass() {} public MyBaseClass(object arg) {}
This isn't a holy war, this isn't a question of which is better. What
Why isn't Visual Studio 2005 generating a serialization setting when I set the project
Why isn't Collection.remove(Object o) generic? Seems like Collection<E> could have boolean remove(E o); Then,

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.