V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
qwertyegg
V2EX  ›  Java

Reflection 一问

  •  
  •   qwertyegg · Jul 19, 2019 · 2557 views
    This topic created in 2477 days ago, the information mentioned may be changed or developed.

    下面这段代码,为什么第二行和第三行的第二 /三个参数都是 kotlin.Unit,而不是 kotlin.Int 和 kotlin.String

    fun main(){
        println(Foo::foo.parameters)
        println(Foo2::foo.parameters)
        println(Foo3::foo.parameters)
    }
    
    class Foo{
        fun foo(x: Int, y: String): Boolean{
            return true
        }
    }
    
    class Foo2{
        fun foo(x: Int, y: String): Unit{
            return
        }
    }
    
    class Foo3{
        fun foo(x: Int, y: String){
            return
        }
    }
    

    输出

    [instance of fun Foo.foo(kotlin.Int, kotlin.String): kotlin.Boolean, parameter #1 x of fun Foo.foo(kotlin.Int, kotlin.String): kotlin.Boolean, parameter #2 y of fun Foo.foo(kotlin.Int, kotlin.String): kotlin.Boolean]
    [instance of fun Foo2.foo(kotlin.Int, kotlin.String): kotlin.Unit, parameter #1 x of fun Foo2.foo(kotlin.Int, kotlin.String): kotlin.Unit, parameter #2 y of fun Foo2.foo(kotlin.Int, kotlin.String): kotlin.Unit]
    [instance of fun Foo3.foo(kotlin.Int, kotlin.String): kotlin.Unit, parameter #1 x of fun Foo3.foo(kotlin.Int, kotlin.String): kotlin.Unit, parameter #2 y of fun Foo3.foo(kotlin.Int, kotlin.String): kotlin.Unit]
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1184 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:38 · PVG 01:38 · LAX 10:38 · JFK 13:38
    ♥ Do have faith in what you're doing.