I'm trying to decide between two different ways of writing optimal code for utility classes.
OPTION 1:
public class UtilityClass {
public static ClassB method1(ClassA obj1, ClassA obj2) {
//Some lines of code
}
public static ClassC method2(ClassD obj1, ClassD obj2) {
//Some lines of code
}
}
OPTION 2:
public enum UtilityEnum {
INSTANCE;
public ClassB method1(ClassA obj1, ClassA obj2) {
//Some lines of code
}
public ClassC method2(ClassD obj1, ClassD obj2) {
//Some lines of code
}
}
OPTION 1 I believe gives room for inlining. OPTION 2 will place the instance in heap. Does this affect performance? Which is the most preferable way?