How to write Java function that returns values of multiple data types?

后端 未结 11 1564
耶瑟儿~
耶瑟儿~ 2021-01-03 23:34

For example, I want to create a function that can return any number (negative, zero, or positive).

However, based on certain exceptions, I\'d like the function to re

11条回答
  •  离开以前
    2021-01-04 00:08

    Write a function that returns an Object. Have it either return the Boolean or Integer wrapper objects. Then use instanceof to figure out which to use.

提交回复
热议问题