Scala–Methods vs Functions

An excellent explanation on Scala Methods and Functions:

http://jim-mcbeath.blogspot.in/2009/05/scala-functions-vs-methods.html

Apparently, Methods in Scala are different from Functions. From what I understand, a method is similar to a method in Java – it takes input and produces an output. But a Function is an object. Also takes an input and produces an output, but is an object. Here’s how they’re different:

def f1(x:Int):Int = x*2     //Method that doubles input

def f2 = (x:Int)=>x*2      //Function that doubles input

//f1.toString                    //Cannot be done!

f2.toString                      //Is perfectly valid

For more details, I’d suggest you take a look at Jim McBeath’s explanation.

Advertisements

One thought on “Scala–Methods vs Functions

  1. Hi my name is Donna and I just wanted to drop you a quick note here instead of calling you. I discovered your Scala–Methods vs Functions | Emptiness in void page and noticed you could have a lot more visitors. I have found that the key to running a successful website is making sure the visitors you are getting are interested in your subject matter. There is a company that you can get targeted visitors from and they let you try the service for free for 7 days. I managed to get over 300 targeted visitors to day to my website. Check it out here: http://s.t0m-s.be/2X

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s