Attempt at the Most dynamic FizzBuzz possible in Java I was trying to come up with the most dynamic fizzbuzz answer I could.. and well, this is what I came up with:

public static void main(String[] args) {

    ultraFizzBuzz((Integer arg) -&gt; {
        String retVal = "";
        if(arg % 3 == 0) { retVal += "fizz"; }
        if(arg % 5 == 0) { retVal += "buzz"; }
        return retVal;
    });
}

public static void ultraFizzBuzz(modConditions&lt;Integer&gt; tester) {

    for(int i = 1; i &lt; 100; i++) {
        String result = tester.test(i);
        if(result != "")
            System.out.println(tester.test(i));
        else
            System.out.println(i);
    }
}


In here the modConditions is an interface with a method (test) that returns type String.

What I was basically trying to do is create a super dynamic function that lets you add as many fizzes and buzzes and pops as you wanted.. but I think in the process accidentally made it so you end up writing 90% of the code in a lambda statement everytime you want to call it.

Am I overcomplicating things? Would this be considered bad programming practice?
The most important problem I have with your code is, that it totally fails to achieve the goal you set yourself. This is not dynamic at all. Basically, you take the "normal" method body and put it into a lambda, but this lambda now is a complex function, which contains all of the business logic.

Dynamically, you'd need a collection (probably list for being ordered) of lambdas, which each check a single input value and return an appropriate string representation (i.e. "fizz" or "buzz" or "whatever" or the empty string) and a method to apply this complete list on a single input, accumulate the results and perform the final check whether to output that string or the integer itself.

Thus, start out with something like:

Function&lt;Integer, String&gt; fizz = i -&gt; i % 3 == 0 ? "fizz" : "";
Function&lt;Integer, String&gt; buzz = i -&gt; i % 5 == 0 ? "buzz" : "";
Function&lt;Integer, String&gt; barz = i -&gt; i % 7 == 0 ? "barz" : "";
List&lt;Function&lt;Integer, String&gt;&gt; fizzBuzzList = Arrays.asList(fizz, buzz, barz);


And try to come up with code that operates on such a list. Note: Function is the standard function type with an integer as an input and a string as the output. No need to define your own interface.

If you have achieved this, you can easily add another function to the list to check another value, and then you have achived something that might be considered dynamic.