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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:36:44+00:00 2026-06-13T22:36:44+00:00

I am tired of the below issue. please help? I have a below interface

  • 0

I am tired of the below issue. please help?
I have a below interface

/**
* <T> Type of Timestamp. For ex: Date, long, Calendar etc
* 
*/
public interface TimeStamp<T> extends Comparable<TimeStamp<T>>
{

/**
* Returns the timestamp. 
 * @return 
*/
 public T getTimeStamp();

 }

And in my code I have 2 lists:

    List<FileTimeStamp> f = new ArrayList<FileTimeStamp>();
    List<DefaultTimeStamp> t = new ArrayList<DefaultTimeStamp>();

I want to create a method that takes the above 2 lists containing TimeStamps and then merge them.
Ex:

void merge(List<TimeStamp> l1, List<TimeStamp> l2)
{
    l1.addAll(l2);
    Collections.sort(l1);
}

But the above generates compile time warnings.

void merge(List l1, List l2)
missing type arguments for generic class TimeStamp
where T is a type-variable:
T extends Object declared in interface TimeStamp

How should I define the above method without any compile time warnings? What should be my void merge(List<TimeStamp<????>> l1, List<TimeStamp<????>> l2) ???? in left be?

  • 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-06-13T22:36:45+00:00Added an answer on June 13, 2026 at 10:36 pm

    If you care about type safety you must have equal types.

    Solution for your question is:

    public static <T> void  merge(List<T> left, List< ? extends T> right) {
             left.addAll(right);
    }
    

    How this will work:

      List<TimeStamp> timeList = new ArrayList<>();
      List<DefaultTimeStamp> defaultTimeList = new ArrayList<>();
      List<FileTimeStamp> fileTimeList = new ArrayList<>();
    

    We well be able to perform:

     merge(timeList, defaultTimeList);
     merge(timeList, fileTimeList);
    
     merge(timeList, timeList);
     merge(defaultTimeList, defaultTimeList);
     merge(fileTimeList, fileTimeList);
    

    We will not be able to:

     merge(fileTimeList, defaultTimeList);
    

    The key to success is that right list item must be assignalbe to type of items in left list.

    After merge you wan to sort, this is another part of task. To sort List the class that is stored in list should implements interface Comparable

    So we end up with structure like this:

        public interface TimeStamp extends Comparable<TimeStamp> {
    
        }
    
        public interface DefaultTimeStamp extends TimeStamp {
    
        }
    
        public interface FileTimeStamp extends TimeStamp {
    
        }
    

    To merge and sort we need to limie the T to type that implements Comparable<T> at least on T

    And this look like this:

    public static <T extends Comparable<? super T>> void  mergeAndSort(List<T> left, List< ? extends T> right) {
    
        left.addAll(right);
        Collections.sort(left);
    }
    

    So we can say that you have what you want.


    But i would separate the operations and use Iterables.concat(Iterable …), in Combine multiple Collections into a single logical Collection? is describe how it works; for merging and after that i would sort it.

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

Sidebar

Related Questions

Would you please help me with the issue below? I've tried 3 days without
Please help me with the issue mentioned below. My issue is, whether there is
UPDATED - please read further details below original question I have a select form
Please help me in resolving this issue. I'm writing a java SOAP client to
I spent couple of hours to resolve this weird issue. I have date formate
Issue: I have 2 datasources declared on my .aspx file as shown below: <asp:ObjectDataSource
I have an issue in image validation using jQuery Or JavaScript. Please see code
I want to style mail body. I have tried the below methods to style
I need to echo entire content of included file. I have tried the below:
I seem to have hit a wall here and would appreciate some help from

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.