PunyTitan
PunyTitan

Reputation: 277

Can def define a variable in scala?

When I read the source code of Spark, I see this in the RDD class:

def getStorageLevel = storageLevel

What does this statement mean?

Is it defining a variable? If yes, why we don't use var instead? Or is it a function? If yes, why they do not define the parameters and return values at the same time?

Upvotes: 1

Views: 124

Answers (2)

Jörg W Mittag
Jörg W Mittag

Reputation: 369556

Is it defining a variable?

No. It's defining a method.

Or is it a function?

No. It's a method.

If yes, why they do not define the parameters and return values at the same time?

I don't understand the question. There are no parameters here, the method has zero parameter lists.

Upvotes: 1

dcastro
dcastro

Reputation: 68710

Yes, it's a method that always returns the storageLevel value.

Upvotes: 5

Related Questions