What do you understand by apply and unapply methods in scala?

devquora
devquora

Posted On: Feb 22, 2018

 

These methods in scala are used for mapping and unmapping the data between the form and model data.
  • Apply method- this method is used to assemble an object from its components. For eg.- if an employee object needs to be created, then the two components namely- first name and last name should be used and should be composed using the apply method.
  • Unapply method- when we want to decompose the objects from its components, then we make use of this unapply method. Reverse process is followed while making use of the unapply method. So, the employee object can be decomposed into two components namely- first name and last name.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Scala Interview Questions

    What do you mean by a Scala map?

    The collection of key-value pairs where the key can retrieve the values present in a map is known as a scala map. The k..

    Scala Interview Questions

    List the advantages of using scala over other functional programming languages.

    Some of the advantages due to which scala is preferred over other functional programming languages are listed below: As..

    Scala Interview Questions

    Tell the advantages of companion objects when used in Scala?

    Instead of having static methods or variables, scala has singleton or companion objects. These objects are then compile..