• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Java proxy

 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that the Proxy.newProxyInstance method takes an array of interfaces as the second argument. What confuses me is, I can't think of any case where we need to put multiple interfaces as the second argument since we have to cast the proxied object as one type (unless Java has the multitype casting I'm unaware of). Could anyone give me an example where we need to pass multiple interface into this method call?
thanks
 
Marshal
Posts: 25677
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's an example on this page: http://www.javacodegeeks.com/2012/08/creating-java-dynamic-proxy.html. It doesn't use an explicit list, instead it uses a list returned by another method (Class.getInterfaces). The article doesn't go into detail about what happens if the class in question implements more than one interface, or for that matter if it doesn't implement any interfaces, but I speculate that particular code fragment might be why that method takes an array of interface classes rather than just an interface class.
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, basically, only one interface will be relevant at a time right?
also, does anyone still using Java proxy instead of framework like CGLIB?
 
We're all out of roofs. But we still have tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic