From the course: Build Spring Boot Apps with the Kotlin Programming Language

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

A practical use for reflection

A practical use for reflection

- [Instructor] So let's go and create a new controller. And we'll call this ReportsController. And we'll create the class in here called ReportsController, and we'll need to make this a Controller with the Controller annotation and also let's give our top level class a request mapping, which can be /reports. Okay, so the idea here is that I want to be able to first of all load up this reports page with a list of all of the reports, and I want to find out the list by using reflection. I don't want to have to hard code the list of reports. The idea here is that if later on somebody comes and adds a report into our reporting service, that will be automatically picked up on our form. We don't need to change any code to make it work. That's what we're trying to achieve here. So let's write the code that's going to get our list of reports. I think I'm going to put this as a separate, function first of all. And then we'll call it inside a function that's going to display the page. So let's…

Contents