Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling safe varargs in Java 6 and 7, clarification needed

Tags:

java

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.

like image 912
James Raitsev Avatar asked Oct 29 '12 18:10

James Raitsev


2 Answers

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

like image 54
Louis Wasserman Avatar answered Nov 02 '22 15:11

Louis Wasserman


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

like image 2
yatul Avatar answered Nov 02 '22 14:11

yatul