19
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Javaでif (a == 1 && a‬ == 2 && a‬‬ == 3)でtrueを出力(見えない識別子編)

Last updated at Posted at 2018-01-24

Java でもa == 1 && a == 2 && a == 3でtrueって出力させたいに対するシンプルかつインチキなアンサー

public class AmazingEqualEqualOperator {
	public static void main(String[] args) {
		int a=1,a=2,a‬‬=3;

		if (a == 1 && a == 2 && a‬‬ == 3) {
			System.out.println("true");
		} else {
			System.out.println("false");
		}
	}
}

目に見えないが変数に使える文字がある。

ここでは 双方向テキストで用いられる制御文字 U+202C Pop directional formatting (PDF) を用いている。つまり、int a と a¥u202C と a¥u202C¥u202C の3種類の見た目が同じ変数を使い分けているだけ。

Character.html#isJavaIdentifierStart(char)
Character.html#isJavaIdentifierPart(char)
を用いることで、Javaの識別子の先頭に用いれる文字か、Javaの識別子の2文字目移行に用いれる文字かを判別することができる。

19
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?