Reputation: 7451
I'm trying to use the java.security.KeyPairGenerator via JRuby 1.7 RC2 as per the following code:
require 'java'
kp = java.security.KeyPairGenerator.getInstance("RSA")
puts kp #java.security.KeyPairGenerator$Delegate@45f177b
However, when I try to call initialize i.e.
kp.initialize(2048)
I get the following exception:-
TypeError: no public constructors for #<Class:0x7efe8e7a>
Any suggestions would be very much appreciated.
Upvotes: 0
Views: 278
Reputation: 11026
This is a little clash between ruby's initialize
method (which is a constructor in the ruby world) and the method in this particular java class.
Normally, one does not call initialize
on a ruby class (you call new
instead), but anyway it seems to be causing some confusion for the interpreter.
If you look at the output of kp.methods
you'll see JRuby has added a initialize__method
to circumvent the clash (note double underscore).
Try this:
require 'java'
kp = java.security.KeyPairGenerator.getInstance("RSA")
kp.initialize__method(2048)
Another technique is to use java_method, which is also useful when the interpreter is having trouble picking the right overload.
E.g.:
m = kp.java_method :initialize, [Java::int]
m.call(2048)
Upvotes: 2