overriding class
Hi,
I wanted to add an extra metod to java.io.File class. So a created my own File class within my package that should override java.io.File class. Looks like this:
publicclass Fileextends java.io.File{
/** Constructor */
public File(String pathname){
super(pathname);
}
public File(String parent, String child){
super(parent,child);
}
public File(java.io.File parent, String child){
super(parent,child);
}
public File(URI uri){
super(uri);
}
public String getExtension(){
String name = getName();
int index = name.lastIndexOf(".");
if (index==-1 || index==0){
return"";
}
String extension = name.substring(index+1);
return extension;
}
}
The problem is, that when i want to use it in a different calss within my package it gives me an Error incompatible types. Part of the other class:
privatestaticvoid indexDirectory(IndexWriter writer, File dir)
throws IOException{
File[] files = dir.listFiles();// Error:incompatible types
File f=null;
for (int i=0; i<files.length; i++){
f = files[i];
String fileExtension = f.getExtension();
if (f.isDirectory()){
indexDirectory(writer, f);
}elseif (indexFileTypes.contains(fileExtension)){
indexFile(writer, f);
}
}
}
Im a beginner in Java so It can be something stupid. But i thaught that subclass should inherit all the methods and also that i can assign the superclass type to the subclass type as the subclass is the same as superclass except it only has one more method.
Can somebody help me with this?
Thanks>

