0

Say I have bunch of Scala classes and I want to compile and package it to JAR.

I want to expose only some limited number of classes to external user of the JAR and "hide" any other classes.

The question: How can I achieve that without explicitly specifying private access modifier for classes to hide?

The problem is that in Scala class is public by default.

The ideal solution would be some Scala compiler option that changes default class modifier to private.

2
  • 2
    I'm fairly sure this is not possible, however you may have a change to achieve this with a compiler plugin. scala-lang.org/old/node/140 However, to be honest, I'm not entirely sure this can be considered a good practice; I would suggest you consider simply using the private keyword so that your code is more portable and easier to reason about by people not familiar with it. Commented Oct 11, 2016 at 11:24
  • I can't think of any language with an equivalent of access modifiers which allows you to change the default with a compiler option. Commented Oct 11, 2016 at 14:02

1 Answer 1

1

I think you answered your own question. Scala provides private for exactly this usecase.

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.