P
Paul J. Lucas
Given:
class Base {
protected Base( int[] a ) {
m_a = a;
}
final int[] m_a;
}
class Derived extends Base {
public Derived() {
super( x ); // illegal
}
private int[] x = new int[1];
}
generates:
cannot reference x before supertype constructor has been called
I need to be able to pass a derive-class-constructed array to a
base class. This is certainly possible in C++. Among other
solutions:
class Base {
protected:
Base( int* a ) {
m_a = a;
}
int* m_a;
};
class Derived : public Base {
public:
Derived() : Base( x = new int[1] ) { }
private:
int* x;
};
This doesn't appear to be possible in Java due to an
unnecessary and annoying restriction. :-(
Is it possible? If so, how?
- Paul
class Base {
protected Base( int[] a ) {
m_a = a;
}
final int[] m_a;
}
class Derived extends Base {
public Derived() {
super( x ); // illegal
}
private int[] x = new int[1];
}
generates:
cannot reference x before supertype constructor has been called
I need to be able to pass a derive-class-constructed array to a
base class. This is certainly possible in C++. Among other
solutions:
class Base {
protected:
Base( int* a ) {
m_a = a;
}
int* m_a;
};
class Derived : public Base {
public:
Derived() : Base( x = new int[1] ) { }
private:
int* x;
};
This doesn't appear to be possible in Java due to an
unnecessary and annoying restriction. :-(
Is it possible? If so, how?
- Paul