You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Peter B. West" <pb...@powerup.com.au> on 2001/09/24 02:52:10 UTC

Indirect array accesses

This is another general Java question.  Again, if you Java gurus know a 
better forum for this stuff, please let me know.

I have found a solution to the problem of dynamic accessing of elements 
of class arrays in classes whose name is known at runtime.  Basically, 
type[] a =
(type[])(Class.forName(classname).getField(arrayname).get(null))

(I haven't tried it that form, mind you.)  Although it is not spelled 
out in the documentation, Field.get(), where the field is an array, 
returns an array reference, and Bob's your uncle.

Out of the solution comes another question.  I have a static initializer 
which can throw a ClassNotFoundException.  How do I handle this?  I 
can't attach a "throws" clause to the "static" keyword.  Do I just catch 
it and throw a RuntimeException?

Peter
-- 
Peter B. West  pbwest@powerup.com.au  http://powerup.com.au/~pbwest
"Lord, to whom shall we go?"


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: Indirect array accesses

Posted by "Peter B. West" <pb...@powerup.com.au>.
I have found that throwing a RuntimeException in the static initializer 
will, when triggered, eventually generate an ExceptionInInitializerError 
at runtime.

Peter

Peter B. West wrote:

 ....
> Out of the solution comes another question.  I have a static initializer 
> which can throw a ClassNotFoundException.  How do I handle this?  I 
> can't attach a "throws" clause to the "static" keyword.  Do I just catch 
> it and throw a RuntimeException?
> 
> Peter


-- 
Peter B. West  pbwest@powerup.com.au  http://powerup.com.au/~pbwest
"Lord, to whom shall we go?"


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org