Created
March 13, 2011 16:19
-
-
Save jthoenes/868213 to your computer and use it in GitHub Desktop.
This file contains 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
public static <l> L[] createHeapPollution(L... args) { | |
Object[] elements = args; | |
elements[0] = Arrays.asList(12, 12); | |
return args; | |
} | |
public static void main(String... args) { | |
List<string>[] polluted = createHeapPollution(Arrays.asList("a", "b", "c")); | |
// java.lang.Integer cannot be cast to java.lang.String | |
String element = polluted[0].get(0); | |
} |
This file contains 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
public void perfom(String userInput) { | |
userInput = userInput.toLowerCase(Locale.US); | |
if (userInput.equals("YES")) { | |
performYes(); | |
} else if (userInput.equals("NO")) { | |
performNo(); | |
} else if (userInput.equals("CANCEL")) { | |
performCancel(); | |
} else if (userInput.equals("YES TO ALL")) { | |
performYesToAll(); | |
} else if (userInput.equals("NO TO ALL")) { | |
performNoToAll(); | |
} else { | |
throw new IllegalArgumentException(); | |
} | |
} |
This file contains 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
int dec = 153; | |
int hex = 0x99; | |
int oct = 0231; | |
int bin = 0b10011001; | |
Assert.assertEquals(dec, hex); | |
Assert.assertEquals(hex, oct); | |
Assert.assertEquals(oct, bin); | |
Assert.assertEquals(bin, dec); |
This file contains 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
try { | |
callWithReflection(arg); | |
} catch (NoSuchMethodException e) { | |
throw new RuntimeException(e); | |
} catch (IllegalAccessException e) { | |
throw new RuntimeException(e); | |
} catch (InvocationTargetException e) { | |
throw new RuntimeException(e); | |
} catch (ClassNotFoundException e) { | |
throw new RuntimeException(e); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} |
This file contains 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
@SafeVarags | |
public static <l> L[] createHeapPollution(L... args) { | |
return args; | |
} | |
public static void main(String... args) { | |
List<string>[] unpolluted = createNoHeapPollution(Arrays.asList("a", "b", "c")); | |
String element = unpolluted[0].get(0); | |
} |
This file contains 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
public void perfom(char userInput) { | |
userInput = Character.toUpperCase(userInput); | |
switch (userInput) { | |
case 'Y': | |
performYes(); | |
break; | |
case 'N': | |
performNo(); | |
break; | |
case 'C': | |
performCancel(); | |
break; | |
case 'A': | |
performYesToAll(); | |
break; | |
default: | |
throw new IllegalArgumentException(); | |
} | |
} |
This file contains 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
public void perfom(String userInput) { | |
userInput = userInput.toLowerCase(Locale.US); | |
switch (userInput) { | |
case "YES": | |
performYes(); | |
break; | |
case "NO": | |
performNo(); | |
break; | |
case "CANCEL": | |
performCancel(); | |
break; | |
case "YES TO ALL": | |
performYesToAll(); | |
break; | |
case "NO TO ALL": | |
performNoToAll(); | |
break; | |
default: | |
throw new IllegalArgumentException(); | |
} | |
} |
This file contains 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
private long salary = 15_500_000_000L; | |
private int bitmask = 0b1010_1011; |
This file contains 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
Map<patient , Map<LocalDate, List<Medication>>> medications = new HashMap<>(); |
This file contains 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
Map<patient , Map<LocalDate, List<Medication>>> medications = new HashMap<Patient , Map<LocalDate, List<Medication>>>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment