public CompactSuffixTree(SimpleSuffixTree simpleSuffixTree)
{
super(simpleSuffixTree.text);
super.root = compactNodes(simpleSuffixTree.root, 0);
}
The above code is a part of a java implementation of the suffix tree.
Here the CompactSuffixTree
extends AbstractSuffixTree
class which has an attribute "text".
The simpleSuffixTree
class also extends the AbstractSuffixTree
class.
"root" is an attribute in the AbstractSuffixTree
class of type Node
class.
Can anyone please explain what does the code "super(simpleSuffixTree.text);" mean in such a context?
NOTE: the attribute "text" is not present in the simpleSuffixTree
class, which is my main point of confusion.strong text
super(simpleSuffixTree.text);
is a call to the constructor of the super-class AbstractSuffixTree
. simpleSuffixTree.text
is passed to the super-class's constructor, and it's probably used to initialize the "text" property of AbstractSuffixTree
.
It means that the parent constructor is being called. In this case, it'll result in a call to the AbstractSuffixTree( String text )
function.
Subclass Constructors - super
keyword to invoke a superclass's constructor, Here is the CompactSuffixTree
(subclass) constructor that calls the superclass AbstractSuffixTree
constructor and then initialize root attribute in AbstractSuffixTree
class.
this Keyword - You can refer to any member of the current object from within an instance method or a constructor by using this. or you can refer super class public or protected members using this keyword, I will recommend you use this keyword instead of super.root
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.