获取以下Java代码段:
....
else if (true){ //hard-coded as true
///launch methodA
}
else {
///launch methodA (same code as in the ` else if ` statement)
}
....
Run Code Online (Sandbox Code Playgroud)
我想知道的是编译器如何处理这个问题.编译器else if(true)完全删除语句以便不必执行检查是不合逻辑的,即使它被硬编码为真.特别是在Eclipse中,上面的代码是如何解释的?
或者在以下场景中如何:
....
else if (true){ //hard-coded as true
///launch methodA
}
else {
///launch methodBB
}
....
Run Code Online (Sandbox Code Playgroud)
在这种情况下编译器删除else语句不是合乎逻辑的吗?因为在运行时,else语句无法访问.
下面的代码将充当Timer.当我的应用程序根本不加载XML视图时,我正在测试AsynchTask.我的代码应该可以工作,但视图没有打开.我后来做了一些测试并将TextView变量"显示"移动了一下,最终得到了显示的视图,但按下开始按钮不起作用...任何人都可以告诉我如何让TextView更新和运行得当吗?谢谢!
整个布局不显示....
public class MainActivity extends Activity {
timer tim = new timer();
boolean running = true;
int milli = 0;
int secs = 0;
int mins = 0;
int hours = 0;
ArrayList<Lap> laps = new ArrayList<Lap>();
TextView display = (TextView) findViewById(R.id.textView1); //whats going on?
LinearLayout lapsView = (LinearLayout) findViewById(R.id.lapsView);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{
Button b1 = (Button) findViewById(R.id.start);
b1.setOnClickListener(startTimer);
Button b2 = (Button) findViewById(R.id.stop);
b2.setOnClickListener(stopTimer);
}
catch(Exception e1){
}
}
@Override
public boolean …Run Code Online (Sandbox Code Playgroud)