Can I set a private class field using a variable as identifier? How?

No, this doesn’t look to be possible. From the proposal FAQ: Why doesn’t this[‘#x’] access the private field named #x, given that this.#x does? This would complicate property access semantics. Dynamic access to private fields is contrary to the notion of ‘private’. E.g. this is concerning: class Dict extends null { #data = something_secret; add(key, … Read more

Does a private @property create an @private instance variable?

Ellaborating on Kevin’s answer: When you declare a class, e.g.: @interface SomeClass : NSObject { @public id publicIvar; @protected id protectedIvar; @private id privateIvar; } @end the compiler1 decides upon an instance variable layout for that class. This layout determines offsets of instance variables with regard to the address of instances of that class. One … 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 call a private method from outside a java class

use setAccessible(true) on your Method object before using its invoke method. import java.lang.reflect.*; class Dummy{ private void foo(){ System.out.println(“hello foo()”); } } class Test{ public static void main(String[] args) throws Exception { Dummy d = new Dummy(); Method m = Dummy.class.getDeclaredMethod(“foo”); //m.invoke(d);// throws java.lang.IllegalAccessException m.setAccessible(true);// Abracadabra m.invoke(d);// now its OK } }

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