How to make a real private instance variable?

You can use the @private keyword inside the {} to make all subsequent variable declarations private. The default visibility is @protected (which is similar to protected in Java) and that generally works well. You’d have to specifically declare a variable as @public for it to be directly accessible outside the class. This Apple documentation has … Read more

Block a git branch from being pushed

Here’s how the pre-push hook approach works, with a branch called dontpushthis. Create this file as .git/hooks/pre-push: #!/usr/bin/bash if [[ `grep ‘dontpushthis’` ]]; then echo “You really don’t want to push this branch. Aborting.” exit 1 fi This works because the list of refs being pushed is passed on standard input. So this will also … Read more

What exactly is a Private API, and why will Apple reject an iOS App if one is used?

Q. What is the main difference between a “Private API” and a “Non-private API?” Private is one that isn’t publicly defined (there isn’t much to it) Q. Are the “Non-private” APIs only the APIs provided and verified by Apple? Private and Public APIs are both ‘provided’ by Apple but only public APIs are provided for … Read more

Is there any way to access private fields of a struct from another package?

There is a way to read unexported members using reflect (in Go < 1.7) func read_foo(f *Foo) { v := reflect.ValueOf(*f) y := v.FieldByName(“y”) fmt.Println(y.Interface()) } However, trying to use y.Set, or otherwise set the field with reflect will result in the code panicking that you’re trying to set an unexported field outside the package. … Read more

‘public static final’ or ‘private static final’ with getter?

There’s one reason to not use a constant directly in your code. Assume FOO may change later on (but still stay constant), say to public static final int FOO = 10;. Shouldn’t break anything as long as nobody’s stupid enough to hardcode the value directly right? No. The Java compiler will inline constants such as … Read more

Are private members inherited in C#?

A derived class has access to the public, protected, internal, and protected internal members of a base class. Even though a derived class inherits the private members of a base class, it cannot access those members. However, all those private members are still present in the derived class and can do the same work they … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)