Hello,
In static nested classes, do static variables still need to be marked final?
Static variables in Static Classes
Moderator: admin
-
- Posts: 14
- Joined: Fri Sep 09, 2022 5:03 pm
- Contact:
Online
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Static variables in Static Classes
No, they do not need to be marked final. There never was such a restriction on static nested classes.
Before Java 16, non-static nested classes i.e. inner classes were allowed to have a static field only if that field were final. This restriction has been removed in Java 16.
Before Java 16, non-static nested classes i.e. inner classes were allowed to have a static field only if that field were final. This restriction has been removed in Java 16.
If you like our products and services, please help us by posting your review here.
-
- Posts: 14
- Joined: Fri Sep 09, 2022 5:03 pm
- Contact:
Re: Static variables in Static Classes
I see. So does the 1Z0-819 test reflect this change? Or should I still stick to the rule that non-static inner classes can only have a static field if it is final?
Online
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Static variables in Static Classes
This change occurred in Java 16, since 1z0-819 is based on Java 11, this change is not applicable to that exam.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: admin and 36 guests