以下语法的含义是什么:Organization<(Currency, Coupon?) -> Sustenance>()

What's the meaning of this syntax: Organization<(Currency, Coupon?) -> Sustenance>()

我在 an article about type aliases 中偶然发现了这个看似晦涩的语法。

在 Intellij IDEA 中,这段代码可以正常编译:

  class Currency
  class Coupon
  open class Organization<SustenanceT>
  class Sustenance
  class Restaurant : Organization<(Currency, Coupon?) -> Sustenance>()

不知道语法是如何命名的,我找不到关于 Google 的任何信息,因为像“<(”这样的关键字似乎被忽略了。在 Kotlin 文档中,我没有在关于仿制药的页面。唯一相关的搜索结果是 this short section about C function pointers,但解释不多;

此语法的含义是什么,我可以将其应用于哪些用例?

您分析的语法不正确。 <( 不是令牌。让我添加一些空格:

Organization<
    (Currency, Coupon?) -> Sustenance
>

(Currency, Coupon?) -> Sustenance 是一个 类型 表示接受 CurrencyCoupon? 作为参数的函数,以及 returns Sustenance.

此类型然后用作Organisation的类型参数,就像List<String>中的String一样。这究竟意味着什么取决于 Organisation 的类型参数代表什么。从文章来看,好像是“组织做的事情”的意思,所以总而言之,整个类型代表

an organisation that converts currency and coupon to sustenance