I've got a class here, that only contains static
methods, so I call it a helper class, an example:
public class FileUtils {
public static String readFileEntry(final Path path, final String entryKey) throws IOException { }
public static String readAndModifyFileEntry(final Path path, final String entryKey, final UnaryOperator<String> operator) throws IOException { }
}
How should I declare the class (abstract
, final
, static
, etc.), such that it is not possible to instantiate the class? As you are not supposed to do so.
If that is not possible, then what is the best practice?
I'm using Java 8 if that is of any extra help.
You can declare the constructor as private and use the final keyword to prevent extensions :
public final class FileUtils {
private FileUtils() {
}
public static String readFileEntry(final Path path, final String entryKey) throws IOException { }
public static String readAndModifyFileEntry(final Path path, final String entryKey, final UnaryOperator<String> operator) throws IOException { }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With