mindit.io logo
    • retail
      • / retail

        Retail industry, mindit.io

        In the intricate world of retail, mindit.io stands out as your strategic ally.

    • banking
      • / banking
        Woman using a card payment terminal, retail sector, mindit.io

        We partner with European banks on AI transformation, data-platform modernization, and regulatory-grade integration across Benelux, DACH, and UK.

    • financial services
      • / financial services

        Financial services: mindit.io data and AI

        Custom software and data platforms for asset managers, payments providers, and insurers across DACH and the US.

    • healthcare
      • / healthcare

        Doctor with digital tablet in hospital, healthcare sector, mindit.io

        ML and integration solutions for hospitals, health-tech platforms, and national health systems, including Switzerland’s national health sector.

    • hospitality
      • / hospitality
        Hospitality: mindit.io data and AI

        Operational and guest-experience software for hotels, restaurants, and global travel groups.

    • foodtech
      • / foodtech
        Burger and fresh salad, food and beverage sector, mindit.io

        Product engineering for the food industry: from plant-based configurators to supply-chain analytics.

    • manufacturing
      • / manufacturing
        Aerial view of industrial conveyor belt, manufacturing sector, mindit.io

        Industrial software, IoT integration, and data platforms for manufacturers modernizing operations.

    • publishing
      • / publishing
        Publishing: mindit.io AI solutions

        ML platforms and editorial workflow systems for publishers, including Izzard Ink Publishing.

    • real estate
      • / real estate
        Modern residential buildings at dusk, real estate sector, mindit.io

        Property tech and data analytics for real-estate operators and asset managers.

    • telco
      • / telco
        Person using smartphone, telecom sector, mindit.io

        Telecom-grade software for network optimization, customer-facing apps, and AI-driven insights.

    • / company
    • about us
      • / about us

        mindit.io partners and people
        The partner of choice for data & product engineering to drive business growth & deliver an impact within your organization
    • product engineering
      • / product engineering
        We specialize in Software Product Engineering, transforming your concepts into impactful products.
    • technology
      • / technology
        mindit.io AI Native company
        250+ specialists skilled in software, BI, integration, offering end-to-end services from research to ongoing maintenance.
    • methodology
      • / methodology
        Custom software solutions, mindit.io
        We specialize in software product engineering, transforming your concepts into impactful products.
    • careers
      • / careers
        Careers at mindit.io
        Our team needs one more awesome person, like you. Let’s grow together! Why not give it a try?
    • do good
      • / do good
        mindit.io team member do good ESG initiatives by the sea
        We’re a team devoted to making the world better with small acts. We get involved and always stand for kindness.
    • events
      • / events
        From Databricks’ Data + AI Summit to Day-to-Day: How the Latest Announcements Impact Real Deployments – Live Webinar
    • blog
      • / blog
        Databricks just rebuilt the data stack for AI agents. Here is what Retail and Banking should do about it.
        Retail Data Platform Modernization Checklist — BENELUX 2026
    • contact us
      • / contact us
        Request a mindit.io webinar
        We would love to hear from you! We have offices and teams in Romania and Switzerland. How can we make your business thrive?
  • / get in touch

helping enterprises become AI-native organizations

An argument for using Optional as input parameter in Java

This will be a controversial topic, and I am sure that not all will agree with me. There is a debate in the Java community related to the Optional object and whether it should be used only as output or if it can be used as input as well. While most people advocate for only using Optional as output, including some big names from the Java ecosystem, a few don’t agree with them.

In most cases, the presence of an optional parameter in the method signature can pose problems. Still, I believe that a few scenarios were not only using it as input is not only acceptable but recommended. Hopefully, by the end of this article, you will see the advantage of using it as well. And, as with most things in life, don’t overuse it.

Let’s look at the following scenario. You have a complex object, let’s call it Person, that holds some data: first name, last name, age, gender, year of birth, and so on. For simplicity, I won’t write the getter and setter methods.

Just a simple data class that can be modeled as an Entity or a DTO. Nothing fancy for now, but keep in mind possible scenarios of receiving this object as an output from a source.

Next, we have a data source with all the Persons available to the system alongside a method that returns them. However, we don’t always want ALL of them; we want to filter the results by name, gender, age, or combination of these three. And this is where the use of an Optional as an input will add value to the code and make understanding the API easier.

We filter the List’s stream for each filtering parameter that we want and return the remaining items—something like the code below. Keep in mind that it was simplified for clarity.

The power does not stay in the fact that Optional makes the code better, but in the fact that just by reading the method’s signature, you know that it will work just fine regardless of what input parameter combination you use. Only need the ones that are 32 years old? Not a problem. Want those that are also named Popescu? Just provide it!

Yes, you could use it without Optional and do null-checks, however as an external developer, you would have to look over the method’s implementation or documentation to know that you don’t need all of them and that it will work with any combination. Furthermore, this way, you don’t have to write overloaded methods for every variety of possible filtering options.

And I know what you are thinking: Nobody filters an Array this way. First, you would be surprised. And secondly, imagine that instead of having a Data Source that filters a list, you have a Specification that builds a Query using the CriteriaBuilder. This query is later passed to the DB for returning the actual data, just like in the example below.

In this example, for building the predicate, we are using an abstract JPAFilter class that has the utility methods for building predicates, like “equal,” “and,” “like” and “or” predicates. Furthermore, since PersonSpecification implements the Spring Data Specification, it can be used in queries for retrieving the information from the database.

A similar situation is in Spring’s RequestParam attributes where non-mandatory ones are Optional, clearly indicating just by looking over the method’s signature which parameters are optional and which aren’t.

Now, just because Optional exists does not mean you should be using it all the time. Indeed, in most situations having it as input can signify that there is something wrong with the overall architecture of the service or class. But nothing is truly black or white. Hopefully, I managed to convince you that there are situations when using Optional as an input parameter that can help with better understanding the code without reading the documentation.
If you enjoyed this article, check out my blog for more tutorials and insightful information. Find me at LINK , thank you!

Distribute:

/turn your vision into reality

The best way to start a long-term collaboration is with a Pilot project. Let’s talk.