callMethodAs
fun <T> Any.callMethodAs(methodName: String, args: Args, argTypes: ArgTypes = argTypes(), returnType: Class<*>? = null): T
类型安全的方法调用。
找不到方法按 callMethod 语义抛 MemberNotFoundException;目标方法返回 null 会抛 NullPointerException。 期望 null 结果请改用 callMethodAsOrNull。
val name: String = instance.callMethodAs("getName")Content copied to clipboard
自动匹配参数并调用实例方法。
找不到方法按 callMethod 语义抛 MemberNotFoundException;目标方法返回 null 会抛 NullPointerException。 期望 null 结果请改用 callMethodAsOrNull。