Mappers.instantiate issue
Georgiy Rakov
georgiy.rakov at oracle.com
Mon Oct 29 08:08:41 PDT 2012
Hello,
there is an issue in java.util.functions.Mappers.instantiate declaration
if I'm not mistaken. The current declaration is:
public static <T, U> Mapper<T, U> instantiate(Class<? extends T>
clazzT, Class<? extends U> clazzU)
Though I could suppose it should be:
public static <T, U> Mapper<T, U> instantiate(Class<? /_*super*_/ T>
clazzT, Class<? extends U> clazzU)
The point is following type safe code causes IllegalArgumentException
while executing m.map(new Tsub2_Type()).
import java.util.functions.Mapper;
import java.util.functions.Mappers;
public class InstantiateTest {
static class T_Type {
}
public static class U_Type {
public U_Type(Tsub_Type t) {
}
public U_Type(T_Type t) {
}
}
public static class Tsub_Type extends T_Type{
}
public static class Tsub2_Type extends T_Type {
}
public static void main(String []arg) {
Mapper<T_Type, U_Type> m =
Mappers.<T_Type,
U_Type>instantiate(Tsub_Type.class, U_Type.class);
m.map(new Tsub2_Type());
}
}
If declaration is modified as specified above the code simply won't be
compiled.
Please give your comments.
Thanks, Georgiy.
PS: the code is attached for your convenience.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: InstantiateTest.java
Url: http://mail.openjdk.java.net/pipermail/lambda-dev/attachments/20121029/1ab5b287/InstantiateTest.java
More information about the lambda-dev
mailing list