📜  Scala Int self() 方法与示例

📅  最后修改于: 2022-05-13 01:54:24.939000             🧑  作者: Mango

Scala Int self() 方法与示例

self()方法用于返回已指定的相同值。

Method Definition: (Value).selfReturn 
Type: It returns true the same value which has been specified.

示例 1:

Scala
// Scala program of Int self()
// method
   
// Creating object
object GfG
{ 
   
    // Main method
    def main(args:Array[String])
    {
       
        // Applying self method
        val result = (5).self
           
        // Displays output
        println(result)
       
    }
}


Scala
// Scala program of Int self()
// method
   
// Creating object
object GfG
{ 
   
    // Main method
    def main(args:Array[String])
    {
       
        // Applying self method
        val result = (10).self
           
        // Displays output
        println(result)
       
    }
}


输出:
5

示例 2:

斯卡拉

// Scala program of Int self()
// method
   
// Creating object
object GfG
{ 
   
    // Main method
    def main(args:Array[String])
    {
       
        // Applying self method
        val result = (10).self
           
        // Displays output
        println(result)
       
    }
}  
输出:
10