This Code is valid Tiger+ Java:
public class TestCase<B>
{
interface Base
{
}
interface Interface extends Base
{
}
static class Implementation implements Interface
{
}
<T extends B, E extends T> E returnArg(Class<T> c, E e)
{
// do something with c
return e;
}
public static void main(String[] args)
{
TestCase<Base> tc = new TestCase<Base>();
tc.returnArg(Interface.class, new Implementation());
}
}
but the compiler gives:
TestCase.java:28: <T,E>returnArg(java.lang.Class<T>,E) in TestCase<TestCase.Base> cannot be applied to (java.lang.Class<TestCase.Interface>,TestCase.Implementation)
tc.returnArg(Interface.class, new Implementation());
^
1 error
public class TestCase<B>
{
interface Base
{
}
interface Interface extends Base
{
}
static class Implementation implements Interface
{
}
<T extends B, E extends T> E returnArg(Class<T> c, E e)
{
// do something with c
return e;
}
public static void main(String[] args)
{
TestCase<Base> tc = new TestCase<Base>();
tc.returnArg(Interface.class, new Implementation());
}
}
but the compiler gives:
TestCase.java:28: <T,E>returnArg(java.lang.Class<T>,E) in TestCase<TestCase.Base> cannot be applied to (java.lang.Class<TestCase.Interface>,TestCase.Implementation)
tc.returnArg(Interface.class, new Implementation());
^
1 error
- relates to
-
JDK-6359106 Valid generics code does not compile
- Closed