简体   繁体   English

什么回报; (没有价值)是什么意思?

[英]What does return; (without value) mean?

I extracted someone's APK (Android app) to see the Java source code and saw a lot of return; 我提取某人的APK(Android应用程序)来查看Java源代码并看到了很多return; code, even on void methods. 代码,甚至是void方法。

For example: 例如:

public void doSomething(){
do{
    return; //This line makes the code below unreachable and can't compile in Eclipse
    switch(num){
        ...
        default:
            return;
    }
}while(...)
...
}

How come the app seems to run well on my phone? 为什么应用程序似乎在我的手机上运行良好?

I guess return; 我想return; is like a shortcut to break from the method. 就像打破方法的捷径。 Is that right? 是对的吗?

If the method returns void then return; 如果方法返回void则return; just exits out of the method at that statement, not running the following statements. 只退出该语句的方法,而不是运行以下语句。

Yes, that is correct. 对,那是正确的。 Look at the bottom of http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html : 请查看http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html的底部:

The return Statement 退货声明

The last of the branching statements is the return statement. 最后一个分支语句是return语句。 The return statement exits from the current method, and control flow returns to where the method was invoked. return语句从当前方法退出,控制流返回到调用方法的位置。 The return statement has two forms: one that returns a value, and one that doesn't. return语句有两种形式:一种是返回值,另一种是不返回值。 To return a value, simply put the value (or an expression that calculates the value) after the return keyword. 要返回值,只需将值(或计算值的表达式)放在return关键字之后。

return ++count; return ++ count; The data type of the returned value must match the type of the method's declared return value. 返回值的数据类型必须与方法声明的返回值的类型匹配。 When a method is declared void, use the form of return that doesn't return a value. 当方法声明为void时,请使用不返回值的return形式。

return; 返回;

To answer your first question: I assume this code is decompiled. 回答你的第一个问题:我认为这个代码是反编译的。 Note that decompilers are not one to one converters of binary dex code to whatever Java code has been used to generate these binaries. 请注意,反编译器不是二进制dex代码的一对一转换器,而是用于生成这些二进制文件的任何Java代码。 They often have problems with parsing different control structures like loops and switches. 它们经常在解析不同的控制结构(如循环和开关)时遇到问题。 Besides, the binary may be obfuscated, meaning that after compilation the binary is modified in a way to be fully operational, but harder to decompile and reverse engineer (basically to prevent what you're trying to do here :) ). 此外,二进制文件可能会被混淆,这意味着在编译之后,二进制文件会以完全可操作的方式进行修改,但更难以反编译和反向工程(基本上是为了防止你在这里尝试做什么:))。 They can add dead code, like return statement that shouldn't be there, mangle loops and if statements to confuse decompiled code, etc. 他们可以添加死代码,比如不应该存在的return语句,mangle循环和if语句来混淆反编译代码等等。

return关键字基本上用在void方法中,它有助于打破条件语句从方法中出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM