我有一个构造函数,它获取HashSet和HashMap.我需要在一个hashMAp上运行验证检查并将其与hashSet结合使用,因为’super’必须只接收一个hashSet.
当我得到以下错误时,我无法找到方法:在超类型构造函数之前无法引用它
例:
public class A extends B {
public A(HashSet h1, HashMap m1) {
super(new C (h1) ); //h1 should contain changes related to m1..
}
我想做那样的事情:
public class A extends B {
public A(HashSet h1, HashMap m1) {
runMyFunc(h1,m1);
super(new C (h1) );
}
runMyFunc(HashSet h1, HashMap m1){
//do checks
//more checks...
// if something then h1.setUid(m1.get(0))...
return h1;
}
我想将构造函数转换为私有,然后像这样运行它:
public class A extends B {
private A(HashSet h1) {
super(new C (h1) );
}
public A(HashSet h1, HashMap m1) {
runMyFunc(h1,m1);
this(h1);
}
但它也没有用.
你能建议吗?