We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I wanted to clean up my code, and started adding private and protected where appropriate. But when I tried it out, it didn't seem to affect anything.
I didn't see anything specifically about it, but after searching I wondered if they'd really only matter if I used a .java file instead of .pde.
After further searching, I think it is because my classes are inner classes. I know that means that they can see outer class private members and vice-versa, but it hadn't occurred to me that they could see into each other. Is this right?
Here's what I used to try it out. I tested it by making a new TryMe2 in setup().
thanks andy
class TryMe1 {
TryMe1() {
_myNumber = 6;
}
private void myMethod() {
println("me1 " + _myNumber);
}
private int _myNumber;
}
class TryMe2 {
TryMe2() {
TryMe1 tm = new TryMe1();
println("me2 " + tm._myNumber);
println("me2 => me1");
tm.myMethod();
}
}
Answers
http://forum.processing.org/two/discussion/10964/how-does-one-go-about-making-member-fields-in-a-class-actually-private-in-processing
http://forum.processing.org/two/discussion/comment/43709/#Comment_43709
Thank you very much. I'll disagree with you about protected being better than private, because I think they have different uses, rather than one being better than the other.
A big part of me wants to leave the access levels in my sketch, but if they aren't actually doing anything, I'm probably better off taking them back out. Oh, well.
thanks andy
You can make top level classes by creating Java tabs e.g. if this tab is called Foo.java then this is a top level tab and the access specifiers work as designed
I agree with your assessment :)
@quark
Did you mean Foo.java?
My mistake have gone back and corrected it. :\">