2013-04-15 53 views
0

我怎样才能为变量的堆栈质量asssignment?如何使质量分配

我声明的变量

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",无所谓只是一个例子)

+2

这是不是Java的语言功能。 – noahlz

回答

6
not_id = not_section = ... = not_status = ""; 
0

阵列或其他集合用for循环。任何你能想到的解决方案都会降低到这个水平。如果值不是均匀阵列中的属于,你必须让每个你想在实际分配给一些变量赋值一个。这是没有办法的。

一般来说,如果你想初始化为复杂的东西所有的对象,你可以创建与封装了一个默认的构造函数的包装类,但是这将是你的情况远远更多的工作。例如

Foo a = new Foo(1, 2, 3); 
Foo b = new Foo(1, 2, 3); 

可与

Foo a = new FooW(); 

FooW与调用super(1, 2, 3)默认构造函数扩展Foo所取代。

-1

环路它

for (String s: list) { 
      s=""; 
      //or 
      s="a"; 
     } 
+0

没有列表... – jamp

+0

“我宣布变量列表” ....任何方式祝贺第一个downvote :)。我同意..我的假设是错误的。 –

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 = ""; 
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"; 
+2

这是假定每个字符串,但是'not_id'已声明。 –