Created
October 28, 2011 08:08
-
-
Save bussiere/1321849 to your computer and use it in GitHub Desktop.
inverse randomly true and false in java program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Field; | |
import java.lang.reflect.Modifier; | |
// comment pourrir un code en douce :p | |
public class TEst | |
{ | |
public static class EverythingIsTrue | |
{ | |
public static void main(String args[]) throws Exception | |
{ | |
System.out.format("Everything is %s \n", false); // "Everything is true" | |
System.out.format("Everything is %s \n", true); | |
} | |
static | |
{ | |
try | |
{ | |
int random = (int)(Math.random() * 2); | |
int random2 = (int)(Math.random() * 2); | |
System.out.println(random); | |
System.out.println(random2); | |
Field Mat = Boolean.class.getField("FALSE"); | |
Mat.setAccessible(true); | |
Field Xenashura = Boolean.class.getField("TRUE"); | |
Xenashura.setAccessible(true); | |
Field modifiersField = Field.class.getDeclaredField("modifiers"); | |
modifiersField.setAccessible(true); | |
modifiersField.setInt(Mat, Mat.getModifiers() & ~Modifier.FINAL); | |
modifiersField.setInt(Xenashura, Xenashura.getModifiers() & ~Modifier.FINAL); | |
if (random == 1) Mat.set(null, true); | |
if (random2 == 1)Xenashura.set(null, false); | |
} | |
catch (Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment