上一篇用到Objects...objects 和Object[] objects的遇到点小问题,于是我去做了个实验,关于这两个变量传参的问题

代码如下

package com.yck.test;

public class ObjectsTest
{
    public static String  function(Object...objects)
    {
        return "success";
    }
    public static String func(Object[] objs)
    {
        return "victory";

    }
    public static void main(String[] args)
    {
        System.out.println("function(Objects...object) 不带参数"+function());
        //System.out.println("func(Object[] objs) 不带参数"+func()); //自动报错

        System.out.println("function(Objects...object) 带单个参数"+function(1));
        //System.out.println("func(Object[] objs) 带单个参数"+func(1)); //自动报错
        //System.out.println("func(Object[] objs) 带单个参数"+func(1)); //自动报错

        Object[] objs = {1,"String",true};
        System.out.println("function(Objects...object) 带数组参数"+function(objs));
        System.out.println("func(Object[] objs) 带数组参数"+func(objs));

        System.out.println("function(Objects...object) 带多个变量"+function(1,"hello",true));
    }

}

结果如下

很明显,我们可以得出以下结论

当形参为Object[]数组时,调用该方法必须为一个数组

当形参为Object...objects时,调用就相当灵活了,可以不带参数,可以带一个参数或者多个参数,也可以带数组作为参数

最新文章

  1. Jupyter Notebook 27绝技——27 Jupyter Notebook tips, tricks and shortcuts
  2. VirtualBox安装Ubuntu教程
  3. Permission Lists Assigned to a User
  4. db2 数据类型
  5. PLSQL游标使用
  6. QQ互联第三方登陆 redirect uri is illegal(100010)
  7. DFS算法(——模板习题与总结)
  8. 关于window.open窗口的resize事件
  9. 1.7 flask 的组件 wtfroms使用
  10. POJ 3614 Sunscreen (优先队列)
  11. oracle单行函数 之 时间函数
  12. xcode10 - 打ipa上蒲公英或者fire.im
  13. MySQL数据库执行sql语句创建数据库和表提示The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB' to have it working
  14. Linux的操作系统I2C驱动架构解说
  15. Alone
  16. Hello,移动WEB—Viewport_Meta标签
  17. 1.6 NBU Catalog备份还原
  18. python学习之-- 故障记录汇总
  19. 下载谷歌地图封锁IP解决办法
  20. git版本管理与github

热门文章

  1. 禅道SQA
  2. IDEA+Java:Selenium+Maven+TestNG基本WebUI自动化测试环境搭建
  3. DNS,TCP,IP,HTTP,socket,Servlet概念整理
  4. 【js】name 与 array 的纠葛 - 坑
  5. linux查看是否安装Apache,mysql,python等
  6. linux(centos)下安装PHP的PDO扩展
  7. H5微信通过百度地图API实现导航方式二
  8. Linux 下安装jetty服务器
  9. 爬虫协议robots
  10. JavaScript高程--<script>标签