How can I access a private constructor of a class?

One way to bypass the restriction is to use reflections: import java.lang.reflect.Constructor; public class Example { public static void main(final String[] args) throws Exception { Constructor<Foo> constructor = Foo.class.getDeclaredConstructor(); constructor.setAccessible(true); Foo foo = constructor.newInstance(); System.out.println(foo); } } class Foo { private Foo() { // private! } @Override public String toString() { return “I’m a Foo … Read more

An enclosing instance that contains is required

You’re trying to use the non-static inner positionObj class without an instance of Secretary for it to belong to. A non-static inner class must belong to an instance of its parent class You should probably change positionObj to a normal class or a static inner class. Alternatively, you can write someSecretary.new positionObj() to create an … Read more

Why am I getting, “Object reference not set to an instance of an object.” but no line of code is implicated?

This was an incredibly strange issue, but since there it has been solved, it might as well get an answer. I think it’s a bug in the .suo files, as my VS was behaving oddly lately, my programs suddenly started crashing, not building and saying the Office references were not valid. One fix I tried … Read more

Comparing two instances of a class

You should implement the IEquatable<T> interface on your class, which will allow you to define your equality-logic. Actually, you should override the Equals method as well. public class TestData : IEquatable<TestData> { public string Name {get;set;} public string type {get;set;} public List<string> Members = new List<string>(); public void AddMembers(string[] members) { Members.AddRange(members); } // Overriding … Read more