Possible Duplicate:
Why defining class as final improves JVM performance?
I have the following class in my project:
public final class LinkNode
{
public int value;
public LinkNode next;
public LinkNode(int value, LinkNode next)
{
this.value = value;
this.next = next;
}
public LinkNode(int value)
{
this(value, null);
}
}
The slowest line in my code (which is overall quite complex) is where I construct new LinkNode
s.
I found that when I made the class final
, the code ran significantly faster. Why is that?
Is there anything else I can do in this class to optimize this class, specifically the primary constructor?
(For example, are getters/setters faster than public fields? Are there other modifiers I can add? Etc.)