Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
Parameterless Method in Scala
Next article icon

Implicit Parameters In Scala

Last Updated : 07 Dec, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Implicit parameters are the parameters that are passed to a function with implicit keyword in Scala, which means the values will be taken from the context in which they are called. In simpler terms, if no value or parameter is passed to a method or function, then the compiler will look for implicit value and pass it further as the parameter. For example, changing an integer variable to a string variable can be done by a Scala compiler rather than calling it explicitly. When implicit keyword used in the parameter scope of the function, all the parameters are marked as implicit.
Note: A method can only contain one implicit keyword.

Syntax:

def func1(implicit x : Int) // x is implicit
def func2(implicit x : Int, y : Int) // x and y both are implicit
def func3 (x : Int)(implicit y : Int) // only y is implicit 
 

Example 1:

Scala




object Main{
      
    def main(args: Array[String]) 
    {
        val value = 10
        implicit val multiplier = 3
        def multiply(implicit by: Int) = value * by
          
        // Implicit parameter will be passed here
        val result = multiply 
          
        // It will print 30 as a result
        println(result) 
          
    }
}
 
 


Output:
30

Example 2:

Scala




object Main{
      
    def main(args: Array[String])
    {
        val message = "hello "
        implicit val name = "world!"
        def disp(implicit nm : String) = message + nm
          
        // Implicit parameter will be passed here
        val result = disp
          
        // Implicit parameters will not be passed
        val result2 = disp("GFG!") 
        println("With Implicit parameters:")
        println(result) 
        println("Without Implicit parameters:")
        println(result2)     
    }
}
 
 


Output
With Implicit parameters:  hello world!  Without Implicit parameters:  hello GFG!  


Next Article
Parameterless Method in Scala
author
utkarsh_kumar
Improve
Article Tags :
  • Scala
  • Scala

Similar Reads

  • Parameterless Method in Scala
    Prerequisites - Scala | Functions A parameterless method is a function that does not take parameters, defined by the absence of any empty parenthesis. Invocation of a paramaterless function should be done without parenthesis. This enables the change of def to val without any change in the client cod
    2 min read
  • Scala | Repeated Method Parameters
    In Scala, Repeated Method parameters are supported, which is helpful when we don't know the number of arguments a method requires. This property of Scala is utilized in passing limitless parameters to a method defined. Important points : The methods with Repeated Parameters should have each of the p
    2 min read
  • Implicit Conversions in Scala
    Implicit conversions in Scala are the set of methods that are apply when an object of wrong type is used. It allows the compiler to automatically convert of one type to another.Implicit conversions are applied in two conditions: First, if an expression of type A and S does not match to the expected
    3 min read
  • Pure Function In Scala
    In any programming language, there are two types of functions: 1. PURE FUNCTIONS 2. IMPURE FUNCTIONSThere is a basic difference between the two, that is pure function doesn’t change the variable it’s passed and an impure function does. For example, there exists a function which increases the input b
    3 min read
  • Scala Parser Combinators
    When a parser generator is required, some famous parsers that cross our mind are: Yacc and Bison for parsers written in C and ANTLR for parsers written in Java but they are designed to run for specific programming languages. This shortens the scope of use of parsers. However, Scala provides a unique
    3 min read
  • Scala Int ==(x: Int) method with example
    The ==(x: Int) method is utilized to return true if the specified first int value is equal to the second int value, otherwise returns false. Method Definition: (First_Int_Value).==(Second_Int_Value) Return Type: It returns true if the specified first int value is equal to the second int value, other
    1 min read
  • Scala Int !=(x: Int) method with example
    The !=(x: Int) method is utilized to return true if the first int value is not equal to the specified second int value, otherwise returns false. Method Definition: (First_Int_Value).!=(Second_Int_Value) Return Type: It returns true if the first int value is not equal to the specified second int valu
    1 min read
  • Scala List :::() operator with example
    The :::() operator in Scala is utilized to join the List in the argument to the another List. Method Definition: def :::(prefix: List[A]): List[A] Return Type: It returns a list after joining one list to the another one. Example #1: // Scala program of :::() // method // Creating object object GfG {
    1 min read
  • Scala List ::() operator with example
    The ::() operator in Scala is utilized to add an element to the beginning of the List. Method Definition: def ::(x: A): List[A] Return Type: It returns the stated list after adding an element to the beginning of it. Example #1: // Scala program of ::() // method // Creating object object GfG { // Ma
    1 min read
  • Scala List +() operator with example
    The +() operator in Scala is utilized to append an element to the list. Method Definition: def +(elem: A): List[A] Return Type: It returns a list of the stated elements after appending it to an another element. Example #1: // Scala program of +() // method // Creating object object GfG { // Main met
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences