2013-04-15 2 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; 

의 목록을 선언하고 난 그들 중 체하는 사람이 ""에 동일 할 - 빈 문자열

+2

이 자바의 언어 기능이 아닙니다. – noahlz

답변

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

배열 또는 다른 모음 (또는 "a", 중요하지 그냥 예 않습니다) 루프는 for입니다. 당신이 생각해 낼 수있는 해결책은 그만큼 줄어들 것입니다. 값이 배열에 속하도록 동종이 아닌 경우 실제로 할당 할 변수 당 하나의 할당을 가져야합니다. 그 주위에 방법이 없습니다.

일반적으로 모든 객체를 복잡한 것으로 초기화하려면 객체를 캡슐화하는 기본 생성자를 사용하여 래핑 클래스를 만들 수 있지만 훨씬 더 효과적입니다. 예 :

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

FooWsuper(1, 2, 3)를 호출하는 기본 생성자와 Foo를 확장

Foo a = new FooW(); 

로 대체 할 수 있습니다.

-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'를 제외한 모든 문자열을 이미 선언했다고 가정합니다. –