3

I'm working with a Java library in JRuby. I'm reading an object from a file, and I need to pass it as a different object type to a second constructor:

@hmm_model = ObjectInputStream.new(FileInputStream.new(LINGPIPE_MODEL_PATH))
@tagger = HmmDecoder.new(@hmm_model)

@hmm_model is of type ObjectInputStream, and needs to be cast to (HiddenMarkovModel). Obviously, that'd be easy in Java, it would just be:

@tagger = HmmDecoder.new((HiddenMarkovModel)@hmm_model)

But, of course, that doesn't work in JRuby. Is there actually any way to explicitly cast the @hmm_model to be of the correct type?

1 Answer 1

2

So, I'm not very bright. The JRuby JVM interface is smart enough to cast itself, I was making the call to the constructor incorrectly. The actual call is:

@tagger = HmmDecoder.new(@hmm_model.readObject())

and JRuby correctly handles the type conversion to a HiddenMarkovModel.

JRuby: 1 me: 0

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.