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 6354265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:32:57+00:00 2026-05-24T22:32:57+00:00

I’m currently working on refactoring some old code and I found a snippet where

  • 0

I’m currently working on refactoring some old code and I found a snippet where I don’t understand how to properly use Generics for the Swing Application Framework class TaskListener.Adapter.

This is the relevant code snippet:

public void executeTask(Task<?, ?> task, boolean handleException) {
    task.addTaskListener(new TaskListener.Adapter() { /* <-- Two warnings here */
        @Override
        public void failed(TaskEvent event) { /* ... */ }
    });
    getContext().getTaskService().execute(task);
}

1. First I want to get rid of the warnings. “unchecked conversion” and “found raw type”. I tried to change the code to new TaskListener.Adapter<Object, Object>, but then I get the error “cannot be applied to given types”. Is a raw type the only thing I can use here because of the (Task<?, ?> declaration?

2. The declaration of the failed method in org.jdesktop.application.TaskListener.Adapter is public void failed(TaskEvent<Throwable> event), but if I try to change my code to this:

@Override
public void failed(TaskEvent<Throwable> event) { /* ... */ }

I get “method does not override a method from a supertype”. Again I have to go with the raw TaskEvent. Why is that?

Thank you for your help.

EDIT: Javadoc for TaskListener on Jarvana.

  • 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-05-24T22:32:58+00:00Added an answer on May 24, 2026 at 10:32 pm

    You can’t apply an adapter genericised as <Object, Object> to a Task<?, ?> because who knows what the wildcards are? It could be a Task<String, Integer> in which case the adapter’s bounds wouldn’t match and so it wouldn’t be applicable.

    (Well, it might be that in this case they are OK because they’re consumers, but the compiler can’t infer that by itself. If this is the case, then Task.addTaskListener needs to be declared to take a TaskListener<? super T, ? super V> in order to satisfy the compiler.)

    Because of the way the addTaskListener is declared, you need to pass in a listener with the exact same generic bounds. And this is impossible when you declare them as wildcards, since you have no way to refer back to them later. What you need to do instead is make the method generic, which is similar to using ? wildcards except you’re giving them names so you can refer to them later on in the method:

    public <T, V> void executeTask(Task<T, V> task, boolean handleException) {
        task.addTaskListener(new TaskListener.Adapter<T, V>() {
            @Override
            public void failed(TaskEvent event) { /* ... */ }
        });
        getContext().getTaskService().execute(task);
    }
    

    As for the second part, I have no idea – it looks fine to me as well. Perhaps this is some misleading error that comes from the raw types, although that seems unlikely since neither generic parameter is involved in the declaration at all. If the compiler still doesn’t like the override after the above changes, then perhaps the problem is somewhere else (like you’ve accidentally placed the method in the wrong class’ scope, etc.)

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.