为什么此代码给出“无法访问的代码"?错误? [英] Why is this code giving an "unreachable code" error?
本文介绍了为什么此代码给出“无法访问的代码"?错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎找不到解决此问题的方法.我所做的只是声明一个整数,它告诉我代码无法访问.
I can't seem to find a way to fix this problem. All i'm doing is declaring an integer and it's telling me that the code is unreachable.
private class myStack{
Object [] myStack = new Object[50];
private void push(Object a){
int count = 50;
while(count>0){
myStack[count]=myStack[count-1];
count--;
}
myStack[0]=a;
}
private Object pop(){
return myStack[0];
int count2 = 0; //Unreachable Code
}
}
推荐答案
一旦你从一个方法return
,你就会返回到最初调用该方法的方法.您在返回之后放置的任何语句都将毫无意义,因为如果不严重违反程序计数器(在 Java 中可能不可能),您将无法访问这些代码.
Once you return
from a method, you return to the method that called the method in the first place. Any statements you place after a return would be meaningless, as that is code that you can't reach without seriously violating the program counter (may not be possible in Java).
这篇关于为什么此代码给出“无法访问的代码"?错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文