如何为变量堆栈进行质量分配?
我声明了变量列表
String not_id, not_section, not_steet, not_sqTotal, not_sqLiving, not_sqKitchen, not_flat, not_floor, not_floors, not_text, user_phone1, user_phone2, user_contact, not_region, not_district, not_settle, not_price, not_photo, not_date, not_date_till, not_up, not_premium, not_status;
我希望它们中的所有内容都等于""
- 空字符串(或"a"
,只是一个例子并不重要)
答案 0 :(得分:6)
not_id = not_section = ... = not_status = "";
答案 1 :(得分:1)
String not_id, not_section, not_steet, not_sqTotal, not_sqLiving, not_sqKitchen, not_flat, not_floor, not_floors, not_text, user_phone1, user_phone2, user_contact, not_region, not_district, not_settle, not_price, not_photo, not_date, not_date_till, not_up, not_premium, not_status;
not_id = not_section = not_steet = not_sqTotal = not_sqLiving = not_sqKitchen = not_flat = not_floor = not_floors = not_text = user_phone1 = user_phone2 = user_contact = not_region = not_district = not_settle = not_price = not_photo = not_date = not_date_till = not_up = not_premium = not_status = "";
答案 2 :(得分:1)
String not_id=not_section=not_steet=not_sqTotal=not_sqLiving=not_sqKitchen=not_flat=not_floor=not_floors=not_text=user_phone1=user_phone2=user_contact=not_region=not_district=not_settle=not_price=not_photo=not_date=not_date_till=not_up=not_premium=not_status="a";
答案 3 :(得分:0)
具有for
循环的数组或其他集合。你能想到的任何解决方案都会减少到这一点。如果属于数组的值不是同类的,则每个变量必须有一个您希望实际分配给某个值的赋值。没有办法解决这个问题。
通常,如果您希望将所有对象初始化为复杂的东西,您可以使用默认构造函数创建一个包装类,该构造函数将其封装起来,但在您的情况下,这将更加有用。 e.g。
Foo a = new Foo(1, 2, 3);
Foo b = new Foo(1, 2, 3);
可以替换为
Foo a = new FooW();
FooW
使用调用Foo
的默认构造函数扩展super(1, 2, 3)
。
答案 4 :(得分:-1)
循环
for (String s: list) {
s="";
//or
s="a";
}