为什么此代码提供“无法访问的代码”?错误? [英] Why is this code giving an "unreachable code" error?

查看:550
本文介绍了为什么此代码提供“无法访问的代码”?错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到解决此问题的方法。我正在做的就是声明一个整数,它告诉我代码无法访问。

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
    }   
}


推荐答案

从方法返回返回后,您将返回到首先调用该方法的方法。您在返回后发表的任何陈述都是毫无意义的,因为这是您在没有严重违反程序计数器的情况下无法达到的代码(在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆