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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:07:15+00:00 2026-05-24T12:07:15+00:00

I would like to have a generic Interpolator class which can interpolate between instances

  • 0

I would like to have a generic Interpolator class which can interpolate between instances of classes implementing the Interpolatable interface:

interface Interpolatable {
  int getDimension();
  Iterator <? extends Interpolatable> getIterator(double d);
}

class Coordinate extends AnotherClass implements Interpolatable  {
  public int getDimension() {return 3;}
  public Iterator <Coordinate> getIterator (double d) {…}
}

class Interpolator <T extends Interpolatable> {
  Interpolator () {
    int dim = T.getDimension();
  }
  void doSomething (double d) {
    Iterator <? extends Interpolatable> it = T.getIterator(d);
    Interpolatable t = it.next();
    …
  }
}

Of course, the compiler complains about T.getDimension() and T.getIterator(d):

Cannot make a static reference to the non-static method getDimension()/getIterator(double) from the type Interpolatable.

However, the two methods cannot be made static, because they are defined in an interface. And at the time I would use them in Interpolator, I do not have an instance of Coordinate (or any Interpolatable) available.

Any suggestions?

(I understand why interface methods cannot be static; I just lack an idea how to elegantly solve a problem like this.)

  • 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-24T12:07:16+00:00Added an answer on May 24, 2026 at 12:07 pm

    Because of type erasure, you cannot do much with the generic type at runtime. You need to keep an instance or class object around:

    class Interpolator <T extends Interpolatable> {
      private final T target;
    
      Interpolator (T target) {
        this.target = target;
        int dim = target.getDimension();
      }
      void doSomething (double d) {
        Iterator <? extends Interpolatable> it = target.getIterator(d);
        Interpolatable t = it.next();
        …
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic abstract base class from which I would like to derive
I have a system.collections.generic.list(of ListBox) I would like to use the collection classes built-in
I have a generic base repository class for LINQ-to-Entities that can do things like
I would like to have information about the icons which are displayed alongside the
I would like to have the following method as a generic method for any
I would like to have a ComboBox control on a form which will be
I have a generic list of custom objects and would like to reduce that
I have a generic class in C#, like this: public class GenericClass<T> { ...
I would like some feedback on how we can best write a generic function
I have a generic method that accepts a Func<int> and I would like to

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.