Why is this compiling in Java?

Why is this compiling?

B is used in without any general parameters, and this is compiled in Java. What's 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); } } 
+4
source share
2 answers

Here you just use raw type B As well as

  List list = new ArrayList(); // defined as: public interface List<E> 

Quite right; Not recommended.

+7
source

This is for compatibility with pre-J2SE 5.0 Java. You should get a rawtypes warning (pay attention to compiler warnings).

+8
source

Source: https://habr.com/ru/post/1487778/


All Articles