在邊練習 Kotlin 的時候,看方法定義看到了一個型別
Unit
八竿子打不著的無法猜出那是什麼東西,查了一下就把它筆記下來。
官方文件是這樣寫的:
The type with only one value: the Unit object. This type corresponds to the
voidtype in Java.
![]()
所以他其實就是 void
如果有個回傳值,或是 block 的定義是寫 -> Unit 的話,就是可以不用回傳的意思 ![]()
Go to list of users who liked
Share on X(Twitter)
Share on Facebook
More than 5 years have passed since last update.
在邊練習 Kotlin 的時候,看方法定義看到了一個型別
Unit
八竿子打不著的無法猜出那是什麼東西,查了一下就把它筆記下來。
官方文件是這樣寫的:
The type with only one value: the Unit object. This type corresponds to the
voidtype in Java.
![]()
所以他其實就是 void
如果有個回傳值,或是 block 的定義是寫 -> Unit 的話,就是可以不用回傳的意思 ![]()
Register as a new user and use Qiita more conveniently
Go to list of users who liked