This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Generics and java.lang.reflect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generics and java.lang.reflect" Watch "Generics and java.lang.reflect" New topic
Author

Generics and java.lang.reflect

Bill Goldsworthy
Greenhorn

Joined: Dec 21, 2004
Posts: 27
Greetings,

I found an interesting technique (I think) on the web and I'm tailoring it to fit my needs.

I've created an abstract class called TraceProxy which implements java.lang.reflect.InvocationHandler. The idea being that a child of this class will define two methods, before() and after() to add pre/post processing to the invoked object's method calls.

I'm doing this to eventually track performance of my JDBC method calls, but I'd like it to be able to enable this for any method in any object.

Anyways, it works great but I'd like it to handle generic types (well, without any warnings).

My abstract class:



My child class:



For the following code, I'm receiving a warning that the case is checking against the erased type Map. So I guess the type is being stripped away?

I believe I've shown all pertinent sections, is my generic code wrong? Or perhaps it's not possible to maintain the type since it's been converted to a proxy?



I'm still working out how things work with generics in my head so any help is appreciated!

Thanks,
Bill G.


Increasingly, people seem to misinterpret complexity as sophistication, which is baffling - the incomprehensible should cause suspicion rather than admiration. Possibly this trend results from a mistaken belief that using a somewhat mysterious device confers an aura of power on the user. Niklaus Wirth
Bill Goldsworthy
Greenhorn

Joined: Dec 21, 2004
Posts: 27
Sorry, copied wrong section for last example. Should be:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics and java.lang.reflect
 
Similar Threads
Generics and instanceof
Generics
generics...
Generics
Generics