On Thu, Jun 23, 2011 at 1:58 AM, Casper Bang <[email protected]> wrote:
> > I'm torn on the Android R generator running behind, on one hand I > understand its purpose (this is how it works in .NET), on the other > hand I am not certain the folloing code: > > Drawable image = getResources().getDrawable(R.drawable.myimage); > String mystring = this.getString(R.string.mystring); > ImageView imageView = (ImageView) findViewById(R.id.myimageview); > > ...is more consistent, more type-safe or as mockable as: > > Drawable image = getResources().get(Drawable.class, "myimage") > String mystring = getResources().get(String.class, "mystring"); > ImageView imageView = findViewById(imageView.class,"myimageview"); > It seems pretty straightforward to add an abstraction that sits on top of the R files and that offers you the API above. I think Android's R system is probably the best that can be done today in Java from a "type checked XML" standpoint. Ideally, something like Gosu's open type system<http://beust.com/weblog/2011/05/10/open-type-systems/>would probably be my choice: no more code generation, just expose classes that represent the resources in a statically typed way. -- Cédric -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
