Robert Rouse
Robert Rouse

Reputation: 4851

Accessing protected variables from parent class in JRuby

I'm trying to get at the protected variables that are defined in the parent class I have inherited from.

Is this possible? I can't find any documentation saying it is. I've seen tickets that have been closed on earlier versions of JRuby.

Any help would be great.

Edit: To clarify

public class Something {

  protected float somethingelse = 1.0f;

}

I want to get at somethingelse.

Upvotes: 0

Views: 766

Answers (1)

Since this fix, package access, private and protected can be exposed by using field_accessor or field_reader:

require 'java'
java_import 'Something'


class Something
  field_accessor :somethingelse
end

class Stuff < Something
  def anotherstuff
    puts self.somethingelse
  end
end

Stuff.new.anotherstuff

Upvotes: 2

Related Questions