Skip to content

Instantly share code, notes, and snippets.

@jthoenes
Created March 13, 2011 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jthoenes/868213 to your computer and use it in GitHub Desktop.
Save jthoenes/868213 to your computer and use it in GitHub Desktop.
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);
}
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();
}
}
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);
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);
}
@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);
}
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();
}
}
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();
}
}
private long salary = 15_500_000_000L;
private int bitmask = 0b1010_1011;
Map<patient , Map<LocalDate, List<Medication>>> medications = new HashMap<>();
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