Dynamic Return Type in Java method

前端 未结 5 1939
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 14:20

I\'ve seen a question similar to this multiple times here, but there is one big difference.

In the other questions, the return type is to be determined by the parameter.

5条回答
  •  一向
    一向 (楼主)
    2021-02-02 14:50

    If you are really only returning a boolean or a float, then the best you can do is Object.

    If you are returning variable objects, you have to choose a return type with the least common superclass. Primitives don't have a superclass, but they will be boxed into Object representations (like Boolean and Float) which have a common superclass of Object.

提交回复
热议问题