可变参数列表

来源:互联网 发布:qq音乐网络异常 编辑:程序博客网 时间:2024/05/16 08:24
package com.ccit;public class NewVarArgs {static void printArray(Object... args){for(Object obj:args){System.out.print(obj+" ");}System.out.println();}public static void main(String[] args) {printArray(new Integer(47),new Float(3.14),new Double(11.11));printArray(47,3.14F,11.11);printArray("one","two","three");printArray(new A(),new A(),new A());//Integer数组通过使用自动包装而创建printArray((Object[])new Integer[]{1,2,3,4});printArray();}}
有了可变参数,就再也不用显示地编写数组语法了,当你指定参数时,编译器实际上会为你去填充数组。。
0 0