什么是...在方法签名中 [英] What is ... in a method signature

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

问题描述

我在方法签名中第一次看到 ...

I have seen it first time ... in a method signature.

我试图访问.class文件。它有一个如下定义的方法

I tried to access a .class file. It has a method defined as below

public void addGraphData(GraphData... _graphData) {
}

而且GraphData只不过是带有getter和setter的POJO。为什么.class文件显示 GraphData ... _graphData 而不是 GraphData _graphData ??

And that GraphData is nothing but POJO with getters and setters. Why is the .class file displaying GraphData... _graphData instead of GraphData _graphData ??

推荐答案

这是 varargs ,且只能在参数列表中最后使用。最后一个param可以容纳多个对象。

It's varargs and can only be used last in a parameter list. The last param can hold more than one object.

public class C { 

    int i;
    String[] s;

    public C(int i, String... s){
        this.i = i;
        this.s=s;
    }
}
new C(4,"a","b") // will be transformed to int and String[]

查看a和b如何转换为数组。

See how "a" and "b" has transformed into an array.

这篇关于什么是...在方法签名中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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