I’d like to pass a class variable to another class and make it a class variable of that class. How would I do this in the following context?
public class GLCamTest extends Activity {
public float array[] = something;
}
class GLLayer extends GLSurfaceView implements SurfaceHolder.Callback,
Camera.PreviewCallback, Renderer {
//Get class variable here
}
It is difficult to understand wjat you are asking, but here’s a possible answer:
Make class B a subclass of A:
If
arrayis redeclared to bepublic static, you get a situation where there is anarrayattribute that can be referred to asA.arrayorB.array. (Or within eitherAorBas justarray… or even asa.arrayorb.arraywhereaandbhave typesAandBrespectively.)If you cannot create a direct or subtype relationship between
AandB(orA,Band some third class containing the declarations) then you are out of luck. There is no way that they can share declarations.However, you can use static imports to make it seem like the declaration is shared. For example:
Incidentally, it is generally a bad idea to use
staticvariables to share state, especially state represented as bare arrays. This is distinctly non-object-oriented.