Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:02:47+00:00 2026-06-09T20:02:47+00:00

I have created a solution for optionals in Java. public final class Optional<T> {

  • 0

I have created a solution for optionals in Java.

public final class Optional<T> {

    private final T reference;

    private Optional(T reference) {
         this.reference = reference;
    }

    public T get() {
        if (!isPresent()) {
            throw new IllegalStateException("Cannot retrieve reference when absent!");
        }
        return reference;
    }

    public boolean isPresent() {
        return reference != null;
    }

    public static <T> Optional<T> of(T reference) {
        return new Optional<T>(reference);
    }

    public static <T> Optional<T> absent() {
        return of(null);
    }

    public static <T> Optional<T> fromNullable(@Nullable T nullableReference) {
        return of(nullableReference);
    }

}

But when I am using it in my production code, the compiler complains.

This is my production code:

public final class OnsetSequencer {

    private final Onset onset;
    private final Optional<EventManager> eventManager;

    public OnsetSequencer(Onset onset, Optional<EventManager> eventManager) {
        this.onset = onset;
        this.eventManager = eventManager;
    }

    public OnsetSequencer(Onset onset) {
        this(onset, Optional.absent());
    }

    public void sequence() {
        boolean present = eventManager.isPresent();
        if (present) {
            eventManager.get().dispatchEvent(new OnsetBeginEvent(onset));
        }
        onset.begin();
        if (present) {
            eventManager.get().dispatchEvent(new OnsetEndEvent(onset));
        }
        onset.end();
    }

}

The compiler complains at this(onset, Optional.absent()); saying: The constructor OnsetSequencer(Onset, Optional) is undefined

I have tried to fix the issue by changing it to this(onset, Optional<EventManager>.absent());
That syntax is wrong as well.

I am wondering how to fix this issue!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:02:48+00:00Added an answer on June 9, 2026 at 8:02 pm

    I think you want:

    Optional.<EventManager>absent()
    

    I’ve never liked the way of expressing type arguments for generic methods in Java, but such is life. See section 15.12 of the JLS for details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a solution created using visual studio 2008 named, Solution , and i
I've just created a fresh ASP.NET MVC 4 solution and have added 3 Areas
I have looked through these forums to find a solution to this problem, and
I'm trying to use the solution of this post , in order to have
I have created a class named ListCell which is a subclass of UITableViewCell .
I am struggling with a solution to my problem. I have created the code
I have a solution in VS 2008 that creates a DLL. I then use
In Visual Studio you can create a Website, which doesn't have a solution or
For strongly-typed & type-safe solution, I have to do the following step. Create some
I have created a QWidget with a bunch of QToolButtons in it and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.