------------------------
[EMAIL PROTECTED] wrote:
------------------------
>Tom Klaasen wrote:
>> Berin wrote:
>>
>>
>>>>We need a way to invoke the recycle() method in the current implementations,
>>>>so a support for Recyclable is required.
>>>
>>>:) I can do that without requiring that interface! I will use the
>>>reflection facilities to determine if there is a "recycle()" method
>>>with public access, and then call it. I will probably get that done
>>>within the next couple of days.
>>
>>
>> I hope you're joking. In case you're not:
>> http://java.sun.com/docs/books/effective/toc.html , item 35.
>>
>> Right now, I'm refactoring someone else's code who also liked reflection-wizardry.
>It's a bitch.
>
>You will never see the reflection "wizardry", and it is done in a way
>that is called for. The biggest thing is that I need to get Fortress
>to support Recyclable.recycle() without any access to the interface--it
>is in a package that has slow pools, and is unnecessary in the grand
>scheme of things. The Pool itself will perform the checks.
>
>//....
>private final static Class[] EMPTY = new Class[] {};
>
>public void release( Object obj )
>{
> try
> {
> Class objClass = obj.getClass();
> Method meth = objClass.getMethod( "recycle", EMPTY );
>
> if( Modifiers.isPublic( meth.getModifiers() ) )
> {
> meth.invoke( obj, EMPTY );
> }
> }
> catch (Exception e)
> {
> // it is not recyclable
> }
>
> m_available.add( obj );
>}
>
>It's not that bad--not that pretty either. However it allows us to
>handle the Recyclable issues well. Otherwise I have to use reflection
>to determine if it implements
>"org.apache.avalon.excalibur.pool.Recyclable".
You'd use instanceof, not reflection.
> What happens if I have
>something similar in another framework?
Another quick&dirty hack?
>> Just my opinion. We've got such a nice framework right now, with lots of good
>design patterns incorporated, and I would hate to see it wasted in this way.
>
>How is an isolated incident of properly applied reflection a waste?
Reflection always seems "appropriate", but in most cases the guy who codes it just
thinks it's cool. I have fallen into this trap myself, and I have seen others falling
into it also.
If, however, you still think this is the way to go, who am I to stop you. Just
consider me the sign saying "steep ravine ahead". If you're skilled enough to descend
that ravine, by all means go ahead and do it. And a sign doesn't have any knowledge of
the reasons why you want to descend that ravine, and nor do I.
But I'll repeat my sig ;-)
tomK
(String)"".getClass().getConstructor(new Class[] {"".getClass()}).newInstance(new
Object[]{"Reflection is cool"});
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]