What is the equivalent of the C++ Pair in Java?

前端 未结 30 1567
一个人的身影
一个人的身影 2020-11-22 02:29

Is there a good reason why there is no Pair in Java? What would be the equivalent of this C++ construct? I would rather avoid reimplementing my own.<

30条回答
  •  暖寄归人
    2020-11-22 02:57

    Here are some libraries that have multiple degrees of tuples for your convenience:

    • JavaTuples. Tuples from degree 1-10 is all it has.
    • JavaSlang. Tuples from degree 0-8 and lots of other functional goodies.
    • jOOλ. Tuples from degree 0-16 and some other functional goodies. (Disclaimer, I work for the maintainer company)
    • Functional Java. Tuples from degree 0-8 and lots of other functional goodies.

    Other libraries have been mentioned to contain at least the Pair tuple.

    Specifically, in the context of functional programming which makes use of a lot of structural typing, rather than nominal typing (as advocated in the accepted answer), those libraries and their tuples come in very handy.

提交回复
热议问题