java_可变参数&增强for循环
代码比较无厘头,记录看懂的意思
在可变参数的构造方法中,需要使用增强for循环遍历
public class name {
String sex;
public static void main(String[] args) {
name zhangsan = new name();
zhangsan.sex = "男1";
name lisi = new name();
lisi.sex = "男2";
name wangmazi = new name();
wangmazi.sex = "男3";
zhangsan.social(lisi, wangmazi);
}
public void social(name... names) {
for (name name : names) {
System.out.println(sex + "和" + name.sex);
}
}
}