What is the underscore actually doing in this Java code? [closed]
I just began to learn Java.
My friend who is helping me study just sent me this and said 'figure this out'.
Unfortunately I am unable to read this. It looks like Perl to me.
class _{_ _;_(){_=this;}}
What does it mean?
Solution 1:
_
is the class name. It's a very confusing one, but it works!
With the class renamed:
class Something {Something something;Something(){something=this;}}
And cleaned up:
class Something {
Something something;
Something() {
something=this;
}
}
And you can go crazy with this odd naming :)
class _{_ __;_ ____;_(){__=this;____=__;}_(_ ___){__=___;}}
In fact, Unicode is even supported, so this is valid:
class 合法類別名稱{合法類別名稱(){}}
Solution 2:
_
is the class name, underscore is a valid Java variable name, you just need to indent your code to deobfuscate it:
class _{
_ _;
_(){
_=this;
}
}
Like:
class A{
A A;
A(){
A=this;
}
}
Edit: thanks to @Daniel Fischer
Type names and variable names have different namespaces. and for example code
class FOO { FOO FOO; }
is valid in Java.
Summary
-
_
is a class name e.g atclass _{
-
_
is a class member name e.g at_ _;
and_=this
-
_
is a constructor name e.g. at_()
Remember: Java uses six different namespaces:
- Package names,
- type names,
- field (variable) names,
- method names,
- local variable names (including parameters), and
- labels.
In addition, each declared enum has its own namespace. Identical names of different types do not conflict; for example, a method may be named the same as a local variable.