Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing a Java interface at runtime

 
Aiden Nibali
Greenhorn
Posts: 5
  • 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: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out java.lang.reflect.Proxy.
 
Aiden Nibali
Greenhorn
Posts: 5
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic