What are these curly braces doing in this SpringBoot annotation?

temporary_user_name :

I am somewhat new to Java and know almost nothing about Spring / SpringBoot. I saw this line of code today:

@SpringBootTest(classes = {TestRepositoryConfig.class})

I am not really clear what's happening here. From my existing knowledge I infer that I'm looking at something like a key-value parameter, where classes is a parameter passed to the constructor or function called SpringBootTest, and its value is {TestRepositoryConfig.class}.

But I have no idea what those curly braces are doing. Why are they needed? And how could I have answered this question for myself? I didn't know what to search for. "Curly braces java annotation" gave me a deluge of results without any clear answers, unless I wanted to commit to extended reading.

Krystian G :

It means you can supply multiple values as an array:

@SpringBootTest(classes = {TestRepositoryConfig.class, Class2.class, Class3.class})

Think of it as the same syntax as for initializing an array:

String[] array = { "one", "two", "three" };

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=139327&siteId=1