effective-java

Why are public static final array a security hole?

Effective java says: // Potential security hole! static public final Thing[] VALUES = { ... }; Can somebody tell me what is the security hole? ...

How do I make defensive copy of an object?

How do I make defensive copies of a Mutable Object which contains a mutable field in an Immutable Object? class ImmutableObject { private final MutableObject immutable_field; ImmutableObject(MutableObject y) { this.immutable_field = y; } } class MutableObject { public int mutable_field; } The MutableObject does not ha...

What is the right position of literals in String Comparison?

I have if (localName.equals("TaxName")) { but PMD says Position literals first in String comparisons ...

Effective Java item 1 applicability with TDD and dependency injection

I have been reading Effective Java and I have some concerns regarding the first Item "use static factory method instead of constructor" in relation to TDD and dependency injection. The item says that you should avoid having public/protected/default constructor and expose it using static factory. I agree with all the advantages relate...

Is this class fully Immutable?

I am trying to convert a mutable class to an Immutable class following the advices given in Effective Java Item 15 (Minimize Mutability). Can anybody tell me whether the class I created is fully immutable or not? Mutable Class public class Record { public int sequenceNumber; public String id; public List<Field> fields; ...

Grouping Related Constants Shared Between Classes

In Effective Java, Item 17, Josh Bloch argues that putting static members into an interface (and implementing that interface) is a bad practice known as the Constant Interface Antipattern: The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implement...

Adding new methods to superclasses and resulting problems -Likelihood?

Item 16 of Effective Java 2nd edition, favor composition over inheritance says the following "If the superclass acquires a new method in a subsequent release and you have the bad luck to have given the subclass a method with the same signature and a different return type, your subclass will no longer compile. If you’ve given the subcla...