I have three classes:
public abstract class fileHandler<Key extends Object, Value extends Object> {
}
public A extends fileHandler<String, String[]> {
}
public B extends fileHandler<String, String> {
}
Now in my main function i do something like this:
fileHandler file= null;
If (<condition>) {
fileHandler = new A();
} else
fileHandler = new B():
}
But this gives 2 compile time errors:
- Cannot convert A to fileHandler
- Cannot convert B to fileHandler
How can I get rid of these errors as I don't get this error if base class is not generic.
Update:
My class hierarchy is:
class fileHandler<Key, Value> { }
class A extends fileHandler<String, String[]> { }
class B extends fileHandler<String, String> { }
- class C that calls function
gen(object of A)
or
- class D that calls function
gen(object of B)
.
- both C and D are derived from abstract class E.
Now how should I define these functions in C and D and E:
I gave the following:
E:
public abstract void gen (fileHandler A) throws exception;
C:
void gen (fileHandler A) throws exception;
D:
void gen (fileHandler A) throws exception;
C, D, and E give error fileHandler is raw type. Reference to generic type fileHandler(Key, Value) should be parameterized.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…