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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:50:04+00:00 2026-06-03T00:50:04+00:00

I am Currently learning Generics I have this Generic class here package generics.lesson; public

  • 0

I am Currently learning Generics I have this Generic class here

package generics.lesson;

public class Pair<T> {

    private T first;
    private T second;

    public Pair(){ first = null; second = null; }
    public Pair(T first, T second){ this.first = first ; this.second = second;}

    public T getFirst() { return first; }
    public T getSecond() { return second; }

    public void setFirst(T first) { this.first = first; }
    public void setSecond(T second) { this.second = second; }
}

So far I understand this but then I came across this

public static Pair<String> minmax(String[] a)
    {
        if(a.length == 0 || a == null) return null;
        String min = a[0];
        String max = a[0];

        for(int i = 1 ;  i < a.length ; i++)
        {
            if(min.compareTo(a[i])>0) min = a[i];
            if(max.compareTo(a[i])<0) max  = a[i];
        }
        return new Pair<String>(min,max);
    }

What confuses me is this

public static Pair<String> minmax(String[] a)

QUestion

How is this possible? and can a generic class be a method return 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-06-03T00:50:05+00:00Added an answer on June 3, 2026 at 12:50 am

    If this works

    public T getFirst() { return first; } // returns a generic type
    public T getSecond() { return second; } // returns a generic type
    

    (which you said you “understand this”)

    I would expect this to also work

    public static Pair<String> minmax(String[] a) // returns a generic type
    

    BTW: In Java 1.4 neither works, In Java 5.0+ both work. 😉

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

Sidebar

Related Questions

Currently learning Scheme/Racket and have problem running this piece of code. (if (or (<
I am currently learning regex but need this quite urgently. I have a set
I'm currently learning scala. Why this code doesn't work: class GenClass[T](var d : T)
im currently learning python (in the very begining), so I still have some doubts
im currently learning stacks in java and have a quick question. what will the
I'm currently learning SML and I have a question about something I have no
I am currently learning C# and I have a situation where I have a
I am currently learning python in preperation for a class over the summer and
I’m currently learning the Java Collections API and feel I have a good understanding
Hi I'm currently learning Ruby On Rails and I have a little mistake. I

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.