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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:42:54+00:00 2026-06-10T20:42:54+00:00

Possible Duplicate: scala: 'def foo = {1}' vs 'def foo {1}' Why is it

  • 0

Possible Duplicate:
scala: 'def foo = {1}' vs 'def foo {1}'

Why is it that when defining the method main in Scala, there is no need to use a =?

Example:

def main(args:Array[String]) {
    ...

But if one wants to define another function it requires it.

def main(args:Array[String]) **=** {
...

Can someone explain this syntax?

  • 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-10T20:42:55+00:00Added an answer on June 10, 2026 at 8:42 pm

    In Scala, the equals sign in a method declaration tells the compiler that the method returns something. If no equals sign appears, then the compiler knows that that the method doesn’t return anything. This is equivalent to a void method in Java. In Scala, returning nothing is the same as returning Unit.

    scala> def noEquals(x: Int) { x + 1 }
    noEquals: (x: Int)Unit
    
    scala> val y = noEquals(5)
    y: Unit = ()
    

    Compare to an example in which the equals sign appears:

    scala> def hasEquals(x: Int) = { x + 1 }
    hasEquals: (x: Int)Int
    
    scala> val z = hasEquals(5)
    z: Int = 6
    

    In Java, the main method doesn’t return anything (it’s declared as void, as in public static void main(String[] args)). Thus, the Scala version leaves off the equals sign.

    Note also that you can write an main method with an equals sign, as long as the method returns Unit (though this would be against convention). Also, an equals sign is not “required” for other methods… just those that need to return things. It’s perfectly acceptable (and appropriate) to leave off the equals sign if you are writing a method that doesn’t return anything.

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

Sidebar

Related Questions

Possible Duplicate: Functions vs methods in Scala What is the difference between def foo
Possible Duplicate: “new” keyword in Scala Ive noticed that creating certain instances in Scala
Possible Duplicate: Scala: short form of pattern matching that returns Boolean In my scala
Possible Duplicate: val and object inside a scala class? Is there a substantive difference
Possible Duplicate: Scala operator oddity I'm very new to Scala and I read that
Possible Duplicate: Any way to use some Scala for iOS coding? Would it be
Possible Duplicate: What is the rule for parenthesis in Scala method invocation? I'm new
Possible Duplicate: How does Scala's apply() method magic work? I am an absolute beginner
Possible Duplicate: scala and traits on object instances Is it possible to mix in
Possible Duplicate: ++ operator in Scala I want to increment an Int variable in

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.