Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this compile in Java?

Tags:

java

generics

Why does this compile?

B is used in A without any generic parameters, and this compiled in Java. What is going on here?

interface B<T>
{
    public T Foo(T value);
}

public class A
{
    public B What()
    {
        return null;
    }

    public void Foo()
    {
        B x = What();
        x.Foo(123);
    }
}
like image 824
Reactgular Avatar asked Dec 04 '22 10:12

Reactgular


1 Answers

This is for compatibility with pre-J2SE 5.0 Java. You should get a rawtypes warning (take notice of the compiler warnings).

like image 72
Tom Hawtin - tackline Avatar answered Dec 24 '22 20:12

Tom Hawtin - tackline