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

  • Home
  • SEARCH
  • 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 5954783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:01:13+00:00 2026-05-22T18:01:13+00:00

In the following java code, NetBeans complains with or without the @Override statement. If

  • 0

In the following java code, NetBeans complains with or without the @Override statement.
If the Override is not present I get an error that the return types Pair<Interval, Interval> and Pair<ExtendedInterval, ExtendedInterval> are not compatible. The interpreter suggests that I add an @Override statement. However, the same error occurs with the @Override statement.

What’s the best way to make this error go away? I would prefer that the caller not have to cast the returned objects to the correct class.

public class Interval {
    private Date left;
    private Date right;

    public Pair<Interval, Interval> split(Date dt){
        ...
        return new Pair<Interval, Interval>(
                        new Interval(left, dt),
                        new Interval(dt, right));
    }
}

public class ExtendedInterval extends Interval {
    private Data localData;

    @Override
    public Pair<ExtendedInterval, ExtendedInterval> split(Date dt){
        Pair<Interval, Interval> baseInterval = super.split(dt);
        return new Pair<ExtendedInterval, ExtendedInterval>(
                              new ExtendedInterval(localData, baseInterval.first()),
                              new ExtendedInterval(localData, baseInterval.second()));
    } 
}
  • 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-22T18:01:14+00:00Added an answer on May 22, 2026 at 6:01 pm

    Well, you could change the base class method to:

    public Pair<? extends Interval, ? extends Interval> split(Date dt)
    

    I believe that would work.

    The problem is that without that, it simply isn’t type safe. Suppose Pair has a setFirst() method to set the first part of the pair. Then you could have:

    Interval x = new ExtendedInterval();
    Pair<Interval, Interval> pair = x.split(new Date());
    pair.setFirst(new Interval());
    

    That looks fine from the compiler’s point of view, but it’s unlikely that you should be able to call setFirst(Interval) on a Pair<ExtendedInterval, ExtendedInterval>.

    Now all of this applied even if there isn’t actually a setFirst method – because you can’t tell the Java compiler that the Pair<> type itself is covariant; the generic variance is done at the use of the type.

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

Sidebar

Related Questions

When running the following Java code, I get very accurate and consistent results in
I'm getting the following error with some Java code I've written: internal error; cannot
I am following this tutorial, I'm using netbeans 6.5.1 http://www.netbeans.org/kb/docs/java/gui-db-custom.html When I get to
Given the following Java code for generating a binary file: DataOutputStream out = new
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
I'm trying to mimic the following Java code: int[][] multi; // DIMENSIONS ARE UNKNOWN
We try to convert from string to Byte[] using the following Java code: String
I have the following Java 6 code: Query q = em.createNativeQuery( select T.* +
Consider the following piece of Java code. int N = 10; Object obj[] =
I run a Java code with the following command: $ java -Xms4G -Xmx4G myjavacode

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.