Reputation: 23
I am having difficulty understanding this code. I'm unsure if the line that contains a comment is declaring a method or not. I tried googling for list methods but unfortunately didn't find anything. Thank you :)
List<String> getBrands(String color) {//I don't understand this line of code
List<String> brands = new ArrayList<String>();
if(color.equals("amber")) {
brands.add("Jack Amber");
brands.add("Red Moose");
} else {
brands.add("Jail Pale Ale");
brands.add("Gout Stout");
}
return brands;
}
}
Upvotes: 1
Views: 779
Reputation: 919
When designing a method, you need to know the following parts.
public static void myMethod(int parameter) throws someException {
//method body
}
Note :: access modifier,optional specifier and optional exception are optional. Others are required.
In your code,
List<String> getBrands(String color) {
// method body
}
/*
Your access modifier is default (no declaration)
List<String> is return type
getBrands is method name
(String color) is parameter list
{ // .... } is method body
*/
Upvotes: 2
Reputation: 46
It's declaring the method of return type List<String>
, string being the generic type of the list.
Upvotes: 3