| Message: 119181 |
 |
BY: xiao li (expxiaoli) DATE: 2012-12-17 13:25 SUBJECT: throw exception if instance is rewrite #jstr.rb
require 'rubygems'
require 'rjb'
class Jstr
def initialize(str)
class_name = Rjb::import('java.lang.String')
@instance = class_name.new_with_sig('Ljava.lang.String;', str)
end
def replace(ori, other)
@instance = @instance._invoke('replaceAll', 'Ljava.lang.String;Ljava.lang.String;', ori, other) # code A
end
def getStr
@instance.toString # code B
end
end
jstr = Jstr.new("happy li lei")
jstr.replace("lei","lei2")
puts jstr.getStr
running the above code, it throws exception: jstr.rb:15:in `getStr': undefined method `toString' for "happy li lei2":String (NoMethodError)
This exception seems due to rewrite instance at code A. How can I solve it if I wish to rewrite instance? | |