File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing a Java interface at runtime

 
Aiden Nibali
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was just wondering whether it is possible to evaluate Java code at runtime in order to implement an interface. I've tried using the JavaScriptEngine (with javax.script stuff), but for some reason the created class can't be cast into the original interface. Somehow two incompatible interfaces which appear identical are created. Are there any alternative solutions out there?
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out java.lang.reflect.Proxy.
 
Aiden Nibali
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that looks like what I want. You wouldn't believe how difficult it was to find help using Google!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic