Created
June 22, 2013 08:57
-
-
Save dgageot/5840050 to your computer and use it in GitHub Desktop.
Oops, a Lambda tends to forget what's its type.
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
public class Types { | |
interface SMI<T> { | |
T get(T value); | |
} | |
public static void main(String[] args) { | |
SMI<String> inner = new SMI<String>() { | |
@Override | |
public String get(String param) { | |
return param; | |
} | |
}; | |
SMI<String> lambda = (String param) -> param; | |
// public java.lang.String Types$1.get(java.lang.String) | |
System.out.println(inner.getClass().getDeclaredMethods()[0]); // Types are OK | |
// Types.Types$SMI<java.lang.String> | |
System.out.println(inner.getClass().getGenericInterfaces()[0]); // Types are OK | |
// public java.lang.Object Types$$Lambda$1.get(java.lang.Object) | |
System.out.println(lambda.getClass().getDeclaredMethods()[0]); // Oops... Types are erased | |
// interface Types$SMI | |
System.out.println(lambda.getClass().getGenericInterfaces()[0]); // Oops... Types are erased | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment