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

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

Java: accessing private constructor with type parameters

Make sure you use getDeclaredConstructors when getting the constructor and set its accessibility to true since its private. Something like this should work. Constructor<Foo> constructor= (Constructor<Foo>) Foo.class.getDeclaredConstructors()[0]; constructor.setAccessible(true); Foo obj = constructor.newInstance(“foo”); System.out.println(obj); Update If you want to make use of getDeclaredConstructor, pass Object.class as an argument which translates to a generic T. Class fooClazz … Read more

Closest Ruby representation of a ‘private static final’ and ‘public static final’ class variable in Java?

There really is no equivalent construct in Ruby. However, it looks like you are making one of the classic porting mistakes: you have a solution in language A and try to translate that into language B, when what you really should do is figure out the problem and then figure out how to solve it … Read more

Strange behavior when overriding private methods

Inheriting/overriding private methods In PHP, methods (including private ones) in the subclasses are either: Copied; the scope of the original function is maintained. Replaced (“overridden”, if you want). You can see this with this code: <?php class A { //calling B::h, because static:: resolves to B:: function callH() { static::h(); } private function h() { … Read more

How to access private data members outside the class without making “friend”s? [duplicate]

Here’s a way, not recommended though class Weak { private: string name; public: void setName(const string& name) { this->name = name; } string getName()const { return this->name; } }; struct Hacker { string name; }; int main(int argc, char** argv) { Weak w; w.setName(“Jon”); cout << w.getName() << endl; Hacker *hackit = reinterpret_cast<Hacker *>(&w); hackit->name … Read more