What are the warnings about updating the application to use Generics in Java?

I am working with an old Java application written for Java 1.4 before Generics were available. Since then, we have completed the upgrade to Java 6.

We are now exploring the possibility of making changes to Generics support in our collections in order to ensure compile-time security, as well as to preserve the intelligence of the developer.

Are there any warnings or errors that we should be aware of when performing this update?

+5
source share
3 answers
  • Understand how Java generics work and their limitations.
  • Use an IDE with good refactoring support.
  • Do it slowly and carefully.
  • .., , .
  • @SuppressWarning("unchecked"), .

...

+6

, IMHO, , , , , , List<Animal> <> List<Tiger> ... , ? .

, / , , , , ? Object 'catch-alls.' , .

- , Hibernate .., , . , ( ).

, , , , , , .

+1

, .

1) Generics - , , ( -). . , , <?> .

2) , . List<? extends Shape>, List<Shape>. Circle, Shape, List<Circle> List<Shape>, List<? extends Shape>. , , , , .

3) , , List List<?> . , (. ). , , , , , , , , .

+1

All Articles