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 7669539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:36:58+00:00 2026-05-31T15:36:58+00:00

Possible Duplicate: What is the rule for parenthesis in Scala method invocation? I’m new

  • 0

Possible Duplicate:
What is the rule for parenthesis in Scala method invocation?

I’m new to Scala, and I have some confusion with the () on postfix operator

I was told that toLong and toString are postfix operators for any integer, so I tried the following operations:

scala> 7 toString
res18: java.lang.String = 7

scala> 7.toString()
res19: java.lang.String = 7

scala> 7.toString
res20: java.lang.String = 7

scala> 7.toLong
res21: Long = 7 

scala> 7.toLong()
<console>:8: error: Long does not take parameters
              7.toLong()
                      ^

So, when shall one use “()” after an operator? Is there any pattern in that?

Big Thanks!

  • 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-31T15:36:59+00:00Added an answer on May 31, 2026 at 3:36 pm

    First, it’s probably better to think of toLong and toString as being methods on the Int class than postfix operators. Integer literals are objects in Scala, and thus, have methods, two of which are toLong and toString. (Admittedly, the situation is slightly more complex with Int because of implicit conversions, etc, but this is a good way to think about it as a beginner.)

    So what are the rules for dropping parentheses? Scala syntax allows you to drop the () if the method doesn’t take any arguments. However, if a method is defined without the parentheses, then they are not allowed at all:

    class A() {
      def stuff() = "stuff"
      def things = "things"
    }
    
    val a = new A()
    
    a.stuff     // fine
    a.stuff()   // fine
    a.things    // fine
    a.things()  // error!
    

    Finally, when do you drop parentheses and when do you keep them? By convention, in Scala we drop the parentheses for methods that have no side effects and keep them when there are side effects. Obviously this is just a style thing, but it gives an extra clue to readers about how your code works.

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

Sidebar

Related Questions

Possible Duplicate: css rule to disable text selection highlighting On my homepage i have
Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at
Possible Duplicate: What is The Rule of Three? How exactly does std::pair call destructors
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: Properties vs Methods Is there any rule or general best practice as
Possible Duplicate: Css and javascript Not Loading in rewrite rule After using only rewrite
Possible Duplicate: E-mail validation in php? please help I have Ajax sign up form.
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: What is The Rule of Three? The following code outputs garbage at
Possible Duplicate: Ioc/DI - Why do I have to reference all layers/assemblies in entry

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.