For example (using android) if I want to declare a constant of a Camera.Size class I have no apparent way of doing so. I’ve tried:
private static final Camera.Size CAMERA_SIZE = Camera.new Camera.Size(640, 480);
Obviously this didn’t work as you need to have an instance of a camera class to call ‘new’ with, like so:
Camera mCamera = Camera.open();
Camera.Size size = mCamera.new Size(640, 480);
But I can’t do that before before creating the constant. Is there any way around this or is it just impossible to do?
You can’t do that.
Size is a nonstatic inner class of Camera. You can only create a Size within the enclosing class Camera; you cannot construct a new Camera.Size.
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/hardware/Camera.java#Camera.Size
Based on this, I’d say the API for this is written incorrectly. The constructor should have been private, or pkg private to make it clear that you cannot instantiate this class.
You don’t say how you are trying to use it, but it looks like this is an object returned from various methods inside Camera. I don’t see where it’s ever passed into any method. Why do you need to construct it?