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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:56:26+00:00 2026-05-26T02:56:26+00:00

I have the following two interfaces: public interface ParsedFile<K, V extends FileEntry>{…} And public

  • 0

I have the following two interfaces:

public interface ParsedFile<K, V extends FileEntry>{...}

And

public interface MetricsProduces<K, V extends FileEntry>{
    Metrics generateMetrics(ParsedFile<K, V> parsedFile);
}

I have the following generic code the should be able to handle any FileEntry types:

Option<FileDefinition> option = fileContainer.matchFile(file);
if (option.isSome){
  FileDefinition fileDef = option.some();
  ParsedFileFactory<?> factory = filterDefinition.getFactory();
  ParsedFile<?, ?> parsedFile = factory.parseFile(file);
  MetricsProducer<?, ?> metricsProducer = fileDefinition.getMetricsProducer();
  Metrics metrics = metricsProducer.generateMetrics(parsedFile);
}

This block of code is designed to be able to parse any type of file given the appropriate FileDefinition. However I am getting the following compile-time error:

The method generateMetrics(ParsedFile<capture#5-of ?, capture#6-of ? extends FileEntry>) 
in the type MetricsProducer<capture#5-of ?, cature#6-of ? extends FileEntry> 
is not applicable for the arguments 
(ParsedFile<capture#7 of ?, capture#8-of ? extends FileEntry>)

Is there a way to let the compiler know that the “?” type of ParsedFile is the same as the “?” type of MetricsProducer? Is there another option for doing this?

Edit:

I have fixed (as noted this causes a cast warning) the code as follows but was wondering if there is a better option:

public interface MetricsProduces<K, V extends FileEntry>{
    Metrics generateMetrics(ParsedFile<?, ? extends FileEntry> parsedFile);
}

public class TasksMetricsProduces<String, TaskFileEntry> implements MetricsProduces<...>{

    public Metrics generateMetrics(ParsedFile<?, ? extends FileEntry> parsedFile){
         ParsedFile<String, TaskFileEntry> parsedFile2 = (ParsedFile<String, TaskFileEntry>)parsedFile;
    }
}

Edit 2: per comments / suggestions

So I found that if I lock down the types earlier I can do the following:

public interface FileDefinition<K, V extends FileEntry, T extends ParsedFile<K, V>>{...


public void myMethod(){
     for (FileDefinition<?, ?, ?> def : defs){
         process(def);
     }
}

private <K, V extends FileEntry, T extends ParsedFile<K, V>> process(FileDefinition<K, V, T> def){
     Factory<T> factory = def.getFactory();
     MetricsProducer<K, V> producer = def.getMetricsProducer();
     ParsedFile<K, V> parsedFile = factory.parseFile();
     Metrics metrics = producer.generateMetrics(parsedFile);
}

Thanks for the suggestions.

  • 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-26T02:56:26+00:00Added an answer on May 26, 2026 at 2:56 am

    Found that it worked if I locked down the generic types earlier to show the compiler that the types for the objects are the same.

    public interface FileDefinition<K, V extends FileEntry, T extends ParsedFile<K, V>>{...
    
    
    public void myMethod(){
         for (FileDefinition<?, ?, ?> def : defs){
             process(def);
         }
    }
    
    private <K, V extends FileEntry, T extends ParsedFile<K, V>> process(FileDefinition<K, V, T> def){
         Factory<T> factory = def.getFactory();
         MetricsProducer<K, V> producer = def.getMetricsProducer();
         ParsedFile<K, V> parsedFile = factory.parseFile();
         Metrics metrics = producer.generateMetrics(parsedFile);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two interfaces which are generic, IComparable<T> , with method public boolean gt(T
I have two interfaces like these: public interface IMyInterface1 { string prop1 { get;
Consider the following example. I have an interface MyInterface, and then two abstract classes
I have the following two classes: public class Address { public string AddressLine1 {
Given the following two interfaces (these are small examples, not my actual implementation): public
Let's take a glance at the following code in Java. interface FirstInaterface { public
Using Ninject 2.2, I have the following failing test (simplified): public interface IGenericView<T> {
I have the following two methods on an interface for my service layer: ICollection<T>
I have two interfaces, a generic and a non-generic that have an inheritence hierarchy:
I have the following base interface public interface IBaseAction { bool CanAct(...) } and

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.