A company bean

Report a typo

Here is a class named Company with two fields: a name string and a list of employees.

Java
class Company {
    private final String name;
    private final List<String> employees;

    Company(String name, List<String> employees) {
        this.name = name;
        this.employees = employees;
    }
}
Kotlin
class Company(private val name: String, private val employees: List<String>)

An object of this class is created as a bean.

Java
@Bean
public List<String> employees() {
    return List.of(
        "Lillia Barber",
        "Todd Mcloughlin",
        "Jasmine Wu"
    );
}

// 1
@Bean
public Company company(/* 2 */ List<String> employees) {
    return new Company("WorkProject", /* 3 */ employees);
}
Kotlin
@Bean
fun employees(): List<String> {
    return listOf(
        "Lillia Barber",
        "Todd Mcloughlin",
        "Jasmine Wu"
    )
}

// 1
@Bean
fun company( /* 2 */employees: List<String>): Company {
    return Company("WorkProject",  /* 3 */employees)
}

Where can we place the @Autowired annotation?

Select one or more options from the list
___

Create a free account to access the full topic