I totally understand how exciting it is to make full use of the richness of the Java language but sometimes you must stand back and decide whether you have don good or bad. Here I think (and this is only my opinion) you have not done good.
My problem with this is that it is not obvious how to use the mechanism. I would suggest that the transform mechanism should not reside in the Sizes enum, it should be in the Vector.
Something like:
public interface Size { public float getX(); public float getY(); } public static enum Sizes implements Size { WORLD(new Vector2(25.806f, 15.48f)), SCREEN(new Vector2(800f, 480f)); private Vector2 value; private Sizes(Vector2 value) { this.value = value; } public float getX() { return value.getX(); } public float getY() { return value.getY(); } } private static class Vector2 implements Size { final float x; final float y; public Vector2(float x, float y) { this.x = x; this.y = y; } @Override public float getX() { return x; } @Override public float getY() { return y; } public Size transform(Size from, Size to) { return new Vector2(x / from.getX() * to.getX(), y / from.getY() * to.getY()); } }
Your sample transform would then look like:
public void test() { Size onScreen = new Vector2(1,1).transform(Sizes.WORLD, Sizes.SCREEN); }