What is a first class citizen function?

后端 未结 7 1924
清酒与你
清酒与你 2020-12-02 09:05

What is a first class citizen function?

Does Java supports first class citizen function?

Edit:
As mention on Wikepedia

F

7条回答
  •  青春惊慌失措
    2020-12-02 09:58

    Functions are first class citizen means you can pass function anywhere as if it's a variable.

    From Scala

    def isOdd(in: Int) = in % 2 == 1
    val n = (1 to 10).toList
    n.filter(isOdd)
    
    see here: isOdd is a function. passed as if it's a variale.
    

    Objects are first class citizen in Java. A first class citizen is the one that can be passed anywhere. The parallel is from a first class citizen of country are allowed almost everywhere.

    Read:

    • When is a feature considered a “First class citizen” in a programming language/platform?
    • First-class object
    • First-class function

提交回复
热议问题