什么是对象...是什么意思? [英] What does Object... mean?

查看:433
本文介绍了什么是对象...是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能显示的文件:结果
  什么“…”的在Java中意味着什么?结果
   Java数组参数“报关”的语法

任何人都可以证实,如果我看到对象是正确的... 在下面的方法调用的参数:

Can anyone confirm if I'm right in seeing the Object... parameter in the method call below:

public static void setValues(PreparedStatement preparedStatement, Object... values)
    throws SQLException
{
    for (int i = 0; i < values.length; i++) {
        preparedStatement.setObject(i + 1, values[i]);
    }
}    

Object类型的数组?我不记得在Java中以前见过 ...

推荐答案

这是等同于对象[] ,但允许调用者只指定在一个时间值的一个作为参数,编译器会创建一个数组。所以这个调用:

It's equivalent to Object[], but allows the caller to just specify the values one at a time as arguments, and the compiler will create an array. So this call:

setValues(statement, arg1, arg2, arg3);

等同于

setValues(statement, new Object[] { arg1, arg2, arg3 });

查看文档中的可变参数功能(在Java 5中)获得更多信息介绍。

See the documentation for the varargs feature (introduced in Java 5) for more information.

这篇关于什么是对象...是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆