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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:06:10+00:00 2026-05-23T17:06:10+00:00

In the following example the compiler complains on the line: handler.handle(info); with the error:

  • 0

In the following example the compiler complains on the line:
handler.handle(info); with the error:

The method handle(capture#3-of ?
extends T) in the type
Event.Handler is not applicable for the arguments
(T)

Even though the Handler in this case is declared to accept any subclass of T, the compiler wont accept a method call of type T itself.

public class Event<T> {
    public interface Handler<U> {
        public void handle(U info);
    }

    private final Handler<? extends T> handler;
    private final T info;

    public Event(Handler<? extends T> handler, T info) {
        this.handler = handler;
        this.info = info;
    }

    public void doEvent() {
        handler.handle(info);
    }
}

Another interesting feature of this example is if you type: “handler.” in eclipse the following suggestion is given “handle(null info): void”. Somehow the type ‘null’ is being suggested as the acceptable type.

Compiling with javac from the command line still produces a similar error, so this is not just an eclipse issue.

My questions:

  1. Is this the correct behavior of the java compiler?
  2. If it is the correct behavior, what should I be doing to keep type safety for my event class?
  3. What is a null type?
  • 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-23T17:06:11+00:00Added an answer on May 23, 2026 at 5:06 pm

    It’s declared to be a Handler of some type extending T. Imagine T is Object, and you pass in a Handler<String>. That’s fine from the point of view of the constructor – but you then wouldn’t expect to be able to call handler.handle(new Object()) would you? A Handler<String> should only be expected to handle strings, not arbitrary objects.

    Basically you’re looking for contravariance instead of covariance, so you need:

    private final Handler<? super T> handler;
    private final T info;
    
    public Event(Handler<? super T> handler, T info) {
        this.handler = handler;
        this.info = info;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following simple example will produce a compiler error, since I accidently use private
Example: Suppose in the following example I want to match strings that do not
The following source file will not compile with the MSVC compiler (v15.00.30729.01): /* stest.c
The following example from boost bind does not work for me: #include <boost/bind.hpp> struct
In the following example, &amp; and &#916; are OK but &Delta; is not (the
I have the following example, compiled in VS2005, warning level 4: int main(int argc,
Ideally I want a function something like the following (this example doesn't compile): void
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
When I compiled the sample codes of C++, I got following info: c++ excxx_example_database_read.cpp
This confuses me. The following compiles fine under Eclipse. package com.example.gotchas; public class GenericHelper1

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.