-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BeanProperty no longer allowed on private fields. #4481
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4481?orig=1 |
@lrytz said: |
J Robert Ray (jrray) said: If I wish to later remove the test field without breaking ABI, I need to create dummy methods for both pairs of methods. The compiler allows private vars. Why does the compiler disallow private vars when @BeanProperty is also desired? |
@lrytz said: If you want custom getters or setters, you have to write them manually. It's true that this then does not integrate nicely with see also #2215. |
J Robert Ray (jrray) said: My observation in scala 2.8.1 is that the scala accessors take on the visibility of the var, but the Bean accessors are always public. Using scala -print, if I make my var protected, I see: @scala.reflect.BeanProperty private[this] var test: Int = _;
protected <accessor> def test(): Int = line5$$object$$$$iw$$$$iw.this.test;
protected <accessor> def test_=(x$$1: Int): Unit = line5$$object$$$$iw$$$$iw.this.test = x$$1;
def setTest(x$$1: Int): Unit = line5$$object$$$$iw$$$$iw.this.test = x$$1;
def getTest(): Int = line5$$object$$$$iw$$$$iw.this.test(); getTest and setTest are public (as they should be IMO). I really just want to know why private is disallowed. I found your comment in the compiler source, "avoids name clashes with private fields in traits." That's unsatisfying. I promise to not name a private field "setTest" in any trait I inherit from! |
@lrytz said:
Yes, the problem with this solution is that it's wrong. When you have two traits with two private variables of the same name, and both have |
=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
In scala 2.7.7, @BeanProperty was allowed on private fields. In 2.8.1, this is no longer allowed.
=== What is the expected behavior? ===
Allow @BeanProperty on private fields.
One reason to use getters and setters is to hide implementation details. The field should be allowed to be private, otherwise it can "leak out" and be accessed directly, and become part of the ABI of the class.
=== What do you see instead? ===
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: