Can a single Java variable accept an array of either primitives or objects?

前端 未结 6 622
走了就别回头了
走了就别回头了 2021-01-03 12:30

For example, for a single method that reads the elements of an array, how can the programmer allow either an array of objects or an array of primitives to be passed as the p

6条回答
  •  暖寄归人
    2021-01-03 13:14

    In java, all the primitive types have object wrappers. eg. Integer for int, Boolean for boolean, etc. If you are willing to accept an array of object wrappers, then having your method accept Object[] should work for you.

提交回复
热议问题