This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv 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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generics and java.lang.reflect" Watch "Generics and java.lang.reflect" New topic

Generics and java.lang.reflect

Bill Goldsworthy

Joined: Dec 21, 2004
Posts: 27

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!

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

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

wood burning stoves
subject: Generics and java.lang.reflect
It's not a secret anymore!