0

here is the sample code:

@RestController
@RequestMapping("/v1/user")
public class JsonSampleController {

    @GetMapping
    public User getUser() {
        Vehicle vehicle = new Car();
        return new User("y", 4);
    }
}

after the application is started, only Vehicle is loaded into JVM(result of -verbose:class), does Car will be loaded at runtime?

nzomkxia
  • 1,219
  • 4
  • 16
  • 35
  • You already know `-verbose:class`, so how about running `getUser` and see if `Car` gets loaded yourself? Also, why does this matter to you? – Sweeper May 04 '23 at 02:20
  • @Sweeper just curious why `Car` is loaded in runtime instead of starting time, Is it a good reason to post this question? – nzomkxia May 04 '23 at 06:36
  • "Why" is an unclear question - it is unclear what kind of answer will satisfy you. Is a quote from the language/JVM specification satisfy you? i.e. "because the spec says so". – Sweeper May 04 '23 at 06:38
  • @Sweeper can you show me the quote in specification? thanks – nzomkxia May 04 '23 at 07:30
  • Oops, I got confused class loading with class initialisation, which the spec leaves more room for implementation details. Anyway, see [this answer](https://stackoverflow.com/a/34263422/5133585). – Sweeper May 04 '23 at 07:39

0 Answers0