# Brackets in Java Annotation Parameters

Just a quick note for anyone using annotations - I was going through a bunch of code today, where I saw someone using the @SuppressWarnings annotation (which you are probably using if you have generics in your code), and it quickly became clear that the person wasn’t aware of the single-argument support in annotations. They had this in the code everywhere:

1@SuppressWarnings({"unchecked"})
2public void genericsSuck() {
3    // etc.
4}

Even if the parameter in particular for the annotation takes an array, annotations don’t require brackets if you only have one parameter. In those cases you can simply provide the single value, which I think helps the readability quite a bit:

1@SuppressWarnings("unchecked")
2public void genericsSuck() {
3    // etc.
4}

This also works when you are dealing with named parameters. Here is an example from a TestNG @Test annotation - notice that I have even used multiple parameters in this case:

1@Test(dependsOnMethods="otherMethod",
2      dependsOnGroups="unit-tests")
3public void thisMethod() {
4    // Do some testing
5}

If you do have multiple parameters, brackets are then necessary:

1@Test(dependsOnMethods={"otherMethod","mrMethod"},
2      dependsOnGroups="unit-tests")
3public void thisMethod() {
4    // Do some testing
5}