且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将属性获取器作为函数类型传递给另一个函数

更新时间:2023-11-09 23:22:40

您可以通过编写::test(或this::test)来引用吸气剂.

You can reference the getter by writing ::test (or this::test).

编写test::get时,实际上是在String上引用get方法.该方法获取一个索引并返回该索引处的字符.

When you write test::get, you are actually referencing the get method on String. That method takes an index and returns the character at that index.

如果该属性是var,并且您想要引用其setter,则可以编写::test::set.

If the property was a var and you want a reference to its setter, you can write ::test::set.

有关属性引用的更多信息,请参见此处: https://kotlinlang.org/docs/reference/reflection.html#bound-function-and-property-references-since-11

For more info on property references, see here: https://kotlinlang.org/docs/reference/reflection.html#bound-function-and-property-references-since-11