0

When implementing a Scala trait, one has to implement the trait's methods and the simply call the respective static method on Foo$class.class. I'm not sure however how to deal with private fields which are defined in the trait.

That is, if there is a field _something in the trait, if I don't implement _something_$eq() and _something(), the compiler yells at me. My assumption is that I have to create a _something field in my implementing class.

I just want to confirm that this is the correct way of handling this issue.

1 Answer 1

2

Yes, create the private field in the class

Note you also need to call the init method of the Foo$class module

If you want to see exactly what you need to do, just create a Scala class that extends Foo, compile it, and then use a decompiler (jd-gui) to see how it was generated.

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

1 Comment

Thanks. And thanks for the extending the class trick. I did originally look at the scala code in jd-gui, but not with a custom class.

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.