this.file in constructor
in
Programming Questions
•
1 year ago
In the constructor I say this.file (referring to global file variable declared above) equals file (referring to the file variable name in the constructor). Then when I say addFolder(file) I get the error "The method addFolder(MainTab.Node) in the type MainTab is not applicable for the arguments (File)".
This makes sense because I am sending addFolder a file instead of a Node but when I was trying to figure out how to fix it I found out that it works with addFolder(this) but I don't understand why??? "this" should equal the same thing as file no?
This makes sense because I am sending addFolder a file instead of a Node but when I was trying to figure out how to fix it I found out that it works with addFolder(this) but I don't understand why??? "this" should equal the same thing as file no?
- class Node {
- int childCount;
- Node[] children;
- File file;
- Node(File file) {
- this.file = file;
- if(file.isDirectory()) {
- addFolder(file);
- }
Main Tab
McK
- void addFolder(Node folder) {
- if(folderCount == folders.length) {
- folders = (Node[]) expand(folders);
- }
- folders[folderCount++] = folder;
- }
McK
1