Is it possible to specify an arbitrary list of varags in a generic method?

Viewed 68

I am trying to write an interface for REST controllers called GetOne right now this consists of a single method getOne

fun <T> getOne(vararg args : Any) : ResponseEntity<RestResponse<T>>

Ideally I would like to be able to implement this method in any REST controller that has a method for getting one item by id.

While my return type works fine, the method itself can have any number of arguments that are annotated in Spring to map / serialize the fields to the RequestBody / Path Variables / Query Parameters.

I thought I would be able to represent this in my interface as varargs , but this just results in the compiler expecting me to specifically have varargs in my method signature.

Is there a proper way to express this, or can you not do this in kotlin?

1 Answers

Why do you need an interface for the controllers? If you want some common functionality for the implementations (like logging the ID param), you could use Spring AOP.

Related