Skip to content

Instantly share code, notes, and snippets.

@jaspersprengers
Last active February 4, 2018 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaspersprengers/ebe8e65d30c1c806c897b2b89976e292 to your computer and use it in GitHub Desktop.
Save jaspersprengers/ebe8e65d30c1c806c897b2b89976e292 to your computer and use it in GitHub Desktop.
entityConverter
@FunctionalInterface
interface Converter<in E : HasDTO<out D>, out D : DTO> : (E) -> D
@Service
class PreferenceToDto : Converter<Preference, PreferenceDTO> {
override fun invoke(preference: Preference): PreferenceDTO = TODO()
}
@Autowired
lateinit var converter: PreferenceToDto
//invocation with explicit method name
val dto = converter.convert(someEntity)
//the shorthand version
val dto2 = converter(someEntity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment