Kotlin替代品是什么

@Autowired(required=false)
private DependencyC dependencyC;


private Optional<HelloService> optionalHelloService;
public HelloController(Optional<HelloService> helloService) {
    this.optionalHelloService = helloService;
}

最佳答案

您应该使该属性为空,然后:

class HelloController(
    @Autowired(required = false) val helloService: HelloService?
)

10-02 07:39