Created
September 22, 2021 14:49
-
-
Save Tholian/811a8895942628d353d41bcbb51ed63b to your computer and use it in GitHub Desktop.
Java compiler breach
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 class GenericVarArgTest { | |
private static InnerClass myInnerClass; | |
@Test | |
public void testMethodInvocation() | |
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { | |
doSomething(); | |
System.out.println("Done .. all fine"); | |
} | |
private void doSomething() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { | |
myInnerClass = this.new InnerClass(); | |
Method[] methods = myInnerClass.getClass().getMethods(); | |
for (Method aktMethod : methods) { | |
if (aktMethod.getName().equals("printInteger")) { | |
// this will always be okay | |
// Integer myParam = getSomething(); | |
// aktMethod.invoke(myInnerClass, myParam); | |
// this is just ok, for source / target level <= 1.7 | |
aktMethod.invoke(myInnerClass, getSomething()); | |
} | |
} | |
} | |
public static <T> T getSomething() { | |
final T result = (T) Integer.valueOf(1); | |
System.out.println("getSomething will return <T> : " + result); | |
return result; | |
} | |
public class InnerClass { | |
public String printInteger(final Integer aInteger) { | |
final String result = "Integer: " + aInteger; | |
System.out.println("Will return : " + result); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment