开发者

JRuby field_accessor final member

开发者 https://www.devze.com 2023-02-11 16:13 出处:网络
I have a java field that I want to subclass in jruby defined like so: public abstract class FilterObjectStream<S, T> implements ObjectStream<T> {

I have a java field that I want to subclass in jruby defined like so:

public abstract class FilterObjectStream<S, T> implements ObjectStream<T> {
    protected final ObjectStream<S> samples;

I then want to subclass this class and access this member, I have tried to access the protected final member like this, using field_accessor:

class NameSampleDataStream
  field_accessor :samples
end

class HtmlNameSampleDataStream < NameSampleDa开发者_运维百科taStream
  def read
    token = self.samples.read()
    token
  end
end

I am getting an error message:

SecurityError: Cannot change final field 'samples'

I guess the exception answers the question but is there anyway that I can access this variable or is the game up?

I cannot change the java source unfortunately.


Can you try just doing "field_reader"? It's possible to set a final field accessible, but we don't do that for you, and what you want here is just a reader, right?

0

精彩评论

暂无评论...
验证码 换一张
取 消