-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Friday 14 June 2002 18:00, Kenneth B. Russell wrote:
> > public static int getIntForConstant(String constant) {
>
> Simpler and more efficient solution: use Class.getField.
>
> public static int getIntForConstant(String constant) throws
> RuntimeException { try {
> Class c = GLEnum.class;
> java.lang.reflect.Field f = c.getField(constant);
> return f.getInt(c);
> } catch (NoSuchFieldException e) {
> throw new RuntimeException("Field " + constant + " not found");
> }
> }
>
> NoSuchFieldException is a checked exception and its conversion into a
> RuntimeException makes it easier to write code around it without allowing
> silent failures like returning -1 would.
>
i guess thats it - thx for good design tips
so, shall i add it to GLEnmu and GLUEnum as well,
or would you prefere a global GLContext method,
which checks startsWith("GLU") ... ?
cheers, sven
- --
health & wealth
mailto:sgo...@ja...
www : http://www.jausoft.com ; pgp: http://www.jausoft.com/gpg/
voice : +49-521-2399440 ; fax : +49-521-2399442
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE9CiGKHdOA30NoFAARAmg5AKCI9EQ6q9eLrxsfknTk6a7/R1/ScACeLBsp
oZALVvEiPeSPe367QQIOAoY=
=YHVp
-----END PGP SIGNATURE-----
|