Reserved Keywords in Scala

Scala Keywords

Keywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to use as variable names or objects. Doing this will result in a compile-time error.

And one more interesting fact... public and default is not a keyword in Scala, we can use this word as we like as per below example :





Scala contains following keywords:


<-           Delimits a generator from its identifier in a for-loop.

           A single-character (\u2190) alternative to <-.

<:           The upper-bound operator, restricting types to those that are equal to or extend the given type.

<%         The view-bound operator, allowing any type that may be treated as the given type.

=             The assignment operator.

=>           Used in match expressions and partial functions to indicate a conditional expression, in function types to indicate a return type, and in function literals to define the function body.

            A single-character (\u21D2) alternative to =>.

>:            The lower-bound operator, restricting types to those that are equal to or are extended by the given type.

abstract   Marks a class or trait as being abstract and uninstantiable.

case          Defines a matching pattern in match expressions and partial functions.

catch        Catches an exception. An alternate syntax that predates the util.Try monadic collection.

class         Defines a new class.

def            Defines a new method.

do             Part of the do..while loop definition.

else           The second part of an if..else conditional expression.

extends     Defines a base type for a class.

false          One of the two Boolean values.

final          Marks a class or trait as being non extendable.

finally       Executes an expression following a try block. An alternate syntax that predates the util.Try monadic collection.

for             Begins a for-loop.

forSome   Defines an existential type. Existential types are a flexible method for specifying type requirements.

if               The first part of an if..else conditional expression, or the main part of an if conditional statement.

implicit     Defines an implicit conversion or parameter.

import      Imports a package, class, or members of a class to the current namespace.

lazy           Defines a value as being lazy, only defined the first time it is accessed.

match       Begins a match expression.

new           Creates a new instance of a class.

null     A value that indicates the lack of an instance. Has the type Null.

object      Defines a new object.

override    Marks a value or method as replacing the member of the same name in a base type.

package    Defines the current package, an incremental package name, or a package object.

private    Marks a class member as being inaccessible outside the class definition.

protected   Marks a class member as being inaccessible outside the class definition or its sub-classes.

return        Explicitly states the return value for a method. By default, the last expression in a method is used as the return value.

sealed        Marks a class as only allowing sub-classes within the current file.

super         Marks a class member reference as one in the base type, versus one overridden in the current class.

this    Marks a class member reference as one in the current class, versus a parameter with the same name.

throw    Raises an error condition that breaks the current flow of operation and only resumes if the error is caught elsewhere.

trait    Defines a new trait.

true            One of the two Boolean values.

try        Marks a range of code for catching an exception. An alternate syntax that predates the util.Try monadic collection.

type       Defines a new type alias.

val      Defines a new, immutable value.

var      Defines a new, mutable variable.

while       Part of the do..while loop definition.

with              Defines a base trait for a class.

yield             Yields the return value from a for-loop.

Comments

Popular posts from this blog

Transformations and Actions in Spark

How to Convert a Spark DataFrame to Map in Scala

How to Handle and Convert DateTime format in Spark-Scala.