Retrofitting void methods to return its argument to facilitate fluency: breaking change?

后端 未结 3 1714
抹茶落季
抹茶落季 2020-12-24 15:00

\"API design is like sex: make one mistake and support it for the rest of your life\" (Josh Bloch on twitter)

There

3条回答
  •  一个人的身影
    2020-12-24 15:37

    If you can't retrofit, you still can wrap your class into a new one which uses the same methods but with correct returns (MyClassFluent). Or you can add new methods but with different names, instead of Arrays.sort() we could have Arrays.getSorted().

    I think that the solution isn't to force things, just deal with them.

    EDIT: I know I didn't answer to the "retrofitting of void methods" question, but your answer is already really clear.

提交回复
热议问题