Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics and java.lang.reflect

 
Bill Goldsworthy
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bill Goldsworthy
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, copied wrong section for last example. Should be:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic