如果可以,是否应该消除局部变量?
例如,要在Android中保持CPU开启,我可以使用以下代码: PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "abc"); wakeLock.acquire(); 但我认为局部变量powerManager和wakeLock可以消除: ((PowerManager)getSystemService(POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag") .acquire(); 类似的场景出现在iOS警报视图中,例如:from UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"my title" message:@"my message" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; [alert show]; -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ [alertView release]; } 至: [[[UIAlertView alloc] initWithTitle:@"my title" message:@"my message" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show]; -(void)alertView:(UIAlertView *)alertView …