不定(个数)参数的使用
来源:互联网 发布:湖北招生考试软件 编辑:程序博客网 时间:2024/05/18 02:40
不定参数我也不知道真正的中文术语上叫法是叫变元类型,所以才拟定一个这么的叫法.下面是代码,不吝赐教:
/**
* 测试一些数据类型的不定个数传参
* @author Rick
*
*/
public class IndefiniteParamUsage {
/**
* 本函数会产生编译错误,提示说可变参数必须是该方法的最后一个参数,原因可能是地址的排序问题,请详参相关文献
* 编译错误信息:The variable argument type String of the method testFunction$Attention must be the last parameter
* @param stringParm
* @param intParm
* @param charParm
*/
/*private void testFunction$Attention(String ...stringParm, int intParm, char charParm) {
System.out.println("Fn $1: " + intParm + " " + charParm + " " + stringParm);
for(String tempString : stringParm) {
System.out.println("Fn $1: " + intParm + " " + charParm + " " + stringParm);
}
}*/
/**
* 打印测试引用数据类型不定参数
* @param intParm
* @param charParm
* @param stringParm
*/
private void testFunction$1(int intParm, char charParm, String ...stringParm) {
System.out.println("Fn $1: " + intParm + " " + charParm + " " + stringParm);
for(String tempString : stringParm) {
System.out.println("Fn $1: " + intParm + " " + charParm + " " + tempString);
}
}
/**
* 打印测试int数据类型不定参数(两种打印)
* @param stringParm
* @param charParm
* @param intParm
*/
private void testFunction$2(String stringParm, char charParm, int ...intParm) {
System.out.println("Fn $2: " + stringParm + " " + charParm + " " + intParm);
for(int tempInt : intParm) {
System.out.println("Fn $2: " + stringParm + " " + charParm + " " + tempInt);
}
}
private void testFunction$3(String stringParm, int intParm, char ...charParm) {
System.out.println("Fn $3: " + stringParm + " " + intParm + " " + charParm);
for(char tempChar : charParm) {
System.out.println("Fn $3: " + stringParm + " " + intParm + " " + tempChar);
}
}
public static void main(String[] args) {
IndefiniteParamUsage ipu = new IndefiniteParamUsage();
ipu.testFunction$1(1, '美', "美丽的", "美好的", "美妙的");
ipu.testFunction$2("美丽的", '美', 1, 2, 3);
ipu.testFunction$3("美丽的", 1, '美', '丽', '的');
}
}
执行结果是:
Fn $1: 1 美 [Ljava.lang.String;@dcf3e99
Fn $1: 1 美 美丽的
Fn $1: 1 美 美好的
Fn $1: 1 美 美妙的
Fn $2: 美丽的 美 [I@7dc5e7b4
Fn $2: 美丽的 美 1
Fn $2: 美丽的 美 2
Fn $2: 美丽的 美 3
Fn $3: 美丽的 1 [C@1ee0005
Fn $3: 美丽的 1 美
Fn $3: 美丽的 1 丽
Fn $3: 美丽的 1 的
- 不定(个数)参数的使用
- 传递不定个数的参数
- 不定参数的使用
- 不定参数的使用
- Java不定类型,不定个数参数方法的写法
- 不定参数个数的C函数-
- 2.不定个数参数的函数写法
- 如何实现参数个数不定的函数?
- 传不定个数参数的函数写法
- 不定参数个数的C函数
- String... 不定参数个数
- C++不定个数参数
- C语言不定参数个数,可变参数函数使用学习
- 函数中不定参数的处理(函数参数个数不定)
- 不定参数个数函数写法
- C++函数参数个数不定
- C++ 不定个数参数写法
- C#如何实现不定参数个数的函数
- 251. Flatten 2D Vector
- POJ1837-Balance
- 美团编程大赛-优惠券 (set)
- 键盘过滤
- 物联网卡相关的商业模式
- 不定(个数)参数的使用
- 强大的 DynamicWrapperX
- 自定义 注解Annotatino 注入
- 旋转动画
- Java对象销毁和finalize方法
- 大整数的加减乘法,没有除法,你想累死我啊?
- Stereo by SGM
- 查看Linux系统信息
- Java方法传参的值传递和引用传递的区别(code)