简体   繁体   English

反编译的java类有一些特殊的字符

[英]Decompiled java classes have some special characters

I decompiled some java classes and I get a source with special characters: 我反编译了一些java类,我得到一个特殊字符的源:

this.val$b.dispose();
this.val$domainLabel.setText((String)domains_config.get("description"));

what does this mean: this.val$b ? 这是什么意思: this.val$b

According to the Java spec (see http://docs.oracle.com/javase/specs/jls/se5.0/html/lexical.html#3.8 ) $ is a valid value in an identifier. 根据Java规范(请参阅http://docs.oracle.com/javase/specs/jls/se5.0/html/lexical.html#3.8),$是标识符中的有效值。 However, note that "The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems." 但请注意, “$字符应仅用于机械生成的源代码,或者很少用于访问旧系统上的预先存在的名称。”

There are two common reasons for seeing dollar signs in a variable name in decompiled code: 在反编译代码中看到变量名中的美元符号有两个常见原因:

1. Your source code contains an inner class (perhaps, but not necessarily an anonymous one), in which case things for the inner class will have variable and constructor names like outerclass$innerclass . 1.您的源代码包含一个内部类 (可能,但不一定是匿名的),在这种情况下,内部类的内容将具有变量和构造函数名称,如outerclass$innerclass (See, for example http://docstore.mik.ua/orelly/java/exp/ch05_09.htm in the section on how inner classes really work). (参见http://docstore.mik.ua/orelly/java/exp/ch05_09.htm中有关内部类如何工作的部分)。 If the class is anonymous, the names will have a naming scheme/form like outerclass$ followed by outerclass$1 and so forth 如果该类是匿名的,则名称将具有命名方案/表单,如outerclass $,后跟外部类$ 1,依此类推

2. The code has been run through an obfuscator. 2.代码已通过混淆器运行。 An obfuscator meets the criterion of "mechanically generating" the source code, so it can use dollar signs in the ame. 混淆器符合“机械生成”源代码的标准,因此它可以在ame中使用美元符号。 An example would be RetroGuard, which explains in an FAQ on their website , the criterion for using $ in variable and class names. 一个例子是RetroGuard,它在他们网站FAQ中解释了在变量和类名中使用$的标准。 Essentially, the obfuscator uses the $ as a disambiguator and will rename classes or variables with generated names (typically single character letters used when possible to minimize code size), and what is renamed and what isn't depends on the variable's scope, etc. 从本质上讲,混淆器使用$作为消歧器,并使用生成的名称重命名类或变量(通常在可能的情况下使用单个字符字母以最小化代码大小),重命名的内容和不重命名的内容取决于变量的范围等。

In your particular example, val$b looks to me like it might be a variable name that has been obfuscated. 在您的特定示例中,val $ b看起来像是可能是已被混淆的变量名称。

Accordihng to http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html a dollar sign in a variable name is valid, but not recommended, they mention that auto generated code might use it 根据http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html变量名中的美元符号是有效的,但不推荐,他们提到自动生成的代码可能会使用它

below is copied from the link, I bolded parts for emphasis 下面是从链接中复制的,我用粗体部分来强调

Variable names are case-sensitive. 变量名称区分大小写。 A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character " ". 变量的名称可以是任何合法的标识符 - Unicode字母和数字的无限长度序列,以字母开头, 美元符号“$”或下划线字符“ ”。 The convention, however, is to always begin your variable names with a letter, not "$" or " ". 但是,惯例是始终使用字母开头,而不是“$”或“ ”。 Additionally, the dollar sign character, by convention, is never used at all. 此外,按照惯例,美元符号字符根本不会被使用。 You may find some situations where auto-generated names will contain the dollar sign , but your variable names should always avoid using it. 您可能会发现某些情况,其中自动生成的名称将包含美元符号 ,但您的变量名称应始终避免使用它。 A similar convention exists for the underscore character; 对于下划线字符存在类似的约定; while it's technically legal to begin your variable's name with "_", this practice is discouraged. 虽然用“_”开始变量的名称在技术上是合法的,但不鼓励这种做法。 White space is not permitted. 不允许有空白区域。 Subsequent characters may be letters, digits, dollar signs, or underscore characters. 后续字符可以是字母,数字,美元符号或下划线字符。 Conventions (and common sense) apply to this rule as well. 约定(和常识)也适用于此规则。 When choosing a name for your variables, use full words instead of cryptic abbreviations. 为变量选择名称时,请使用完整单词而不是隐藏缩写。 Doing so will make your code easier to read and understand. 这样做可以使您的代码更易于阅读和理解。 In many cases it will also make your code self-documenting; 在许多情况下,它还会使您的代码自我记录; fields named cadence, speed, and gear, for example, are much more intuitive than abbreviated versions, such as s, c, and g. 例如,名为cadence,speed和gear的字段比缩写版本(如s,c和g)更直观。 Also keep in mind that the name you choose must not be a keyword or reserved word 另请注意,您选择的名称不得是关键字或保留字

(Eh, I guess it's actually the answer) (呃,我猜它实际上是答案)

$ has no special meaning in Java, that's simply what the decompiler came up with for the variable name. $在Java中没有特殊含义,这就是反编译器为变量名称提出的内容。

The '$' is valid character in java identifiers. '$'是java标识符中的有效字符。 So "val$b" is just name of the field. 所以“val $ b”只是该领域的名称。 See http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8 http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8

The valid java identifiers can contain letters( a - z , A - Z ), digits( 0 - 9 ), underscores( _ ) and the dollar( $ ). 有效的java标识符可以包含字母( a - zA - Z ),数字( 0 - 9 ),下划线( _ )和美元( $ )。 So the id names you see are just a valid name without any special meaning. 所以你看到的id名称只是一个没有任何特殊含义的有效名称。

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

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