6

What are the main differences between the JDK in terms of handling safe var args?

enter image description here

The above issues a warning in JDK 1.6 -

Type safety: A generic array of List is created for a varargs parameter

  • Why is this warning seen here?
  • What is JDK1.7 doing to suppress it?

Please help me understand.

James Raitsev
  • 92,517
  • 154
  • 335
  • 470

2 Answers2

5

JDK7 added the @SafeVarargs annotation to note when generic varargs are genuinely safe, and applied that annotation to e.g. Collections.addAll.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
2

It's a part of Project Coin. You can look at the proposal here http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000217.html

In short, this warning was moved to method declaration instead of method call. There was a good comment about this: https://stackoverflow.com/a/3819038/891391

Community
  • 1
  • 1
yatul
  • 1,103
  • 12
  • 27