79248150

Date: 2024-12-03 15:15:30
Score: 1.5
Natty:
Report link

How hacky are you allowed to be? The following works, but is "ugly" and you lose the ability to use class-specific methods.

public void myMethod(String... elements) {
  myMethod((Object[]) elements);
}

public void myMethod(Class<?>... elements) {
  myMethod((Object[]) elements);
}

public void myMethod(MyWidget... elements) {
  myMethod((Object[]) elements);
}

private void myMethod(Object... elements) {
  // do it here
}

On the other hand, are you sure that you are not running into an XY-problem? https://xyproblem.info/

I.e., what are you trying to achieve? Is this the best solution for it, or do you have tunnel vision for this problem, which was not your original problem?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Starts with a question (0.5): How
Posted by: D. Kovács