Access restriction on class due to restriction on required library rt.jar?

There’s another solution that also works. Go to the Build Path settings in the project properties. Remove the JRE System Library Add it back; Select “Add Library” and select the JRE System Library. The default worked for me. This works because you have multiple classes in different jar files. Removing and re-adding the JRE lib … Read more

Where is Java Installed on Mac OS X?

Use /usr/libexec/java_home -v 1.8 command on a terminal shell to figure out where is your Java 1.8 home directory If you just want to find out the home directory of your most recent version of Java, omit the version. e.g. /usr/libexec/java_home

Making a mocked method return an argument that was passed to it

Since Mockito 1.9.5+ and Java 8+ You can use a lambda expression, like: when(myMock.myFunction(anyString())).thenAnswer(i -> i.getArguments()[0]); Where i is an instance of InvocationOnMock. For older versions You can create an Answer in Mockito. Let’s assume, we have an interface named MyInterface with a method myFunction. public interface MyInterface { public String myFunction(String abc); } Here … Read more

What is an efficient way to implement a singleton pattern in Java? [closed]

Use an enum: public enum Foo { INSTANCE; } Joshua Bloch explained this approach in his Effective Java Reloaded talk at Google I/O 2008: link to video. Also see slides 30-32 of his presentation (effective_java_reloaded.pdf): The Right Way to Implement a Serializable Singleton public enum Elvis { INSTANCE; private final String[] favoriteSongs = { “Hound … Read more