Sling Model: Post Construct v/s COnstructor
Hello
I am curious about how Sling handles Sling Model.
Say, I instantiate a Sling Model in Sightly, then a PostConstruct is called. Why not a constructor?
Hello
I am curious about how Sling handles Sling Model.
Say, I instantiate a Sling Model in Sightly, then a PostConstruct is called. Why not a constructor?
The @PostConstruct annotation essentially serves as an alternative to a constructor. If you were to employ a constructor in your model, you would observe that, upon its execution, the fields annotated with @Inject are still unassigned. Attempting further initialization with these fields at this point would result in a NullPointerException.

The entire sequence unfolds as follows:
new MyModel()).Sling model annotations: Basics – Adobe Experience Manager Blog (techrevel.blog) (Refer to PostConstruct Annotation section)
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.