Netbeans IDE is good at spotting code that could give you trouble. Why is a warning not issued for
public class Base
{
Base(...)
{
...;
}
public void foo()
{
...;
}
}
public class Child extends Base
{
Child(...)
{
super(...);
foo();
}
}
given that I'm calling the base class function foo() in the child constructor? Of course that's perfectly legitimate as the base object is constructed by the point foo() is called, but a foo() is implicitly a virtual method so really I would expect a warning unless foo() is marked final.
I think that the IDE should issue a warning if you call any base class function from a child class constructor that is not marked as final.
It is easy to enable Java hints in NetBeans. Select "Tools" from the title bar, then select "Options" from the drop-down menu. Choose the "Editor" option and then select the "Hints" tab. At this point, make sure that the "Language" drop-down is set to "Java" (other choices include PHP, JavaScript, and Ruby).
Creating Javadoc StubsPlace the cursor above a method or a class that has no Javadoc, type "/** ", and press Enter . The IDE creates a skeletal structure for a Javadoc comment filled with some content. If you have a Javadoc window open, you will see the changes immediately while you are typing.
To quickly insert constructors from a super class in NetBeans we only have to place the cursor in our class and go to Source | Insert Code... (or press Alt+Insert in Windows). For example we create a new Exception class for our application extending the java. lang.
The Apache NetBeans 13 binary releases require JDK 11+, and officially support running on JDK 11 and JDK 17.
It does.
When you open the file in NetBeans, you should see a yellow lightbulb (hint indicator) next to the call to foo
. It's a suggestion that you either:
If you want it to be more obvious, go to Tools > Options
, or Edit > Preferences
, or Netbeans > Preferences
(depends on your OS).
Choose Editor
Choose Hints
Set Language
to Java
Expand Initialization
Select Problematic call in the constructor
Change Show as
to Error
Click OK
Now the line as well as your file will get a red error badge.
Note, none of this will prevent you from ignoring the indicator. The code is still legal Java, so NB will not prevent you from compiling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With