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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:17:32+00:00 2026-06-04T06:17:32+00:00

In Java 6 I was able to use: public static <T, UK extends T,

  • 0

In Java 6 I was able to use:

public static <T, UK extends T, US extends T> T getCountrySpecificComponent(UK uk, US us) {
    Country country = CountryContext.getCountry();
    if (country == Country.US) {
        return us;
    } else if (country == Country.UK) {
        return uk;
    } else {
        throw new IllegalStateException("Unhandled country returned: "+country);
    }
}

With these repositories:

public interface Repository{
   List<User> findAll();
}

public interface RepositoryUS extends Repository{}

public interface RepositoryUK extends Repository{}

When using these:

RepositoryUK uk = ...
RepositoryUS us = ...

This line compiles in in Java6 but fails in Java7 (error cannot find symbol – as the compiler looks for findAll() on class Object)

List<User> users = getCountrySpecificComponent(uk, us).findAll();

This compiles in Java 7

List<User> users = ((Repository)getCountrySpecificComponent(uk, us)).findAll();

I know this is a rather uncommon use case but is there a reason for this change? Or a way to tell the compiler to be a little “smarter”?

  • 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-04T06:17:34+00:00Added an answer on June 4, 2026 at 6:17 am

    I think T should be bounded to extend Repository. This way the compiler knows that getCountrySpecificComponent returns some repository.

    EDIT:

    It should also be ok to write: public static <T extends Repository> T getCountrySpecificComponent(T uk, T us)

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

Sidebar

Related Questions

I have the following code in Java: public static<T> void doIt(Class<T> t) { T[]
Hi i cant able to use getProcessCpuTime() or getProcessCpuLoad() or getSystemCpuLoad() in my java
Is the Java compiler able to infer the type of a generic static function
I created a new class called Tools inside my com.example.hello workspace. Tools.java: public class
I'm new to Java. I want to be able to input operational characters in
I'd like to know if there is any class in Java able to check,
Are there simple libraries out there (.NET and Java) that are able to validate
I'm able to read the Manifest file inside of my Java code, but I
I've never been able to get the Java 6 splash screen to work. I've
I want to be able to support multiple versions of Java ME without having

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.