call to super() must be the first statement in constructor body

后端 未结 2 1085
不思量自难忘°
不思量自难忘° 2021-01-12 11:36

I\'m writing the constructor of a LoginRequest class which extends a class called JsobObjectRequest (from the Volley framework in Android, but that\'s completely irrelevant

相关标签:
2条回答
  • 2021-01-12 11:56

    Java enforces that the call to super (explicit or not) must be the first statement in the constructor. This is to prevent the subclass part of the object being initialized prior to the superclass part of the object being initialized.

    In your case, you don't do anything but local "trivial computation", so all things considered, it would be okay. However, Java's compiler doesn't go to the level of determining whether statements before a call to super actually do any initialization. It just disallows all statements before super().

    0 讨论(0)
  • 2021-01-12 12:04

    This statement is true.super() must always be the first statement executed inside a subclass constructor. . for details see Java the complete reference by Herbert Schildt...

    0 讨论(0)
提交回复
热议问题