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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:17:39+00:00 2026-05-21T10:17:39+00:00

I have the following classes: public class Obj<T> extends BaseModel { public static final

  • 0

I have the following classes:

public class Obj<T> extends BaseModel {

    public static final String OBJECT = "object";

    public Obj(T object) {
        setObject(object);
    }

    public T getObject() {
        return get(OBJECT);
    }

    public void setObject(T object) {
        set(OBJECT, object);
    }
}

And…

/** This is a 3rd party library class **/
public class BaseModel implements ModelData, Serializable {
  //...members and stuff...

  @SuppressWarnings({"unchecked", "rawtypes"})
  public <X> X get(String property) {
    X obj = null;
    if (start > -1 && end > -1) {
      Object o = map.get(property.substring(0, start));
      String p = property.substring(start + 1, end);
      if (o instanceof Object[]) {
        obj = (X) ((Object[]) o)[Integer.valueOf(p)];
      } else if (o instanceof List) {
        obj = (X) ((List) o).get(Integer.valueOf(p));
      } else if (o instanceof Map) {
        obj = (X) ((Map) o).get(p);
      }
    } else {
      obj = (X) map.get(property);
    }
    return obj;
  }
}

When I compile, I get the following error.

type parameters of <X>X cannot be determined; no unique maximal instance exists for type variable X with upper bounds T,java.lang.Object -> getObject()

It doesn’t happen in Eclipse, which, as far as I can tell, is using the same JDK as my Ant build. I’ve seen the SO thread about the Sun compiler issue, but that seemed to be for static methods declaring types on the fly.

Why am I getting this error, and more importantly, how do I get around it?

So far the only why I’ve found is to cast in my method like this:

@SuppressWarnings({"unchecked"})
public T getObject() {
    return (T) get(OBJECT); //yuck
}

Telling my I’m on crack and this is the proper way is acceptable.

  • 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-21T10:17:40+00:00Added an answer on May 21, 2026 at 10:17 am

    It does not compile because your code expects too much from generics -> i.e., the < X > X part in:

    public <X> X get(String property) { ... }
    

    In the following code:

    public T getObject() {
      return get(OBJECT);
    }
    

    you have to keep in mind that generics are always “unfolded” before the compiler actually starts to compile the Java code. It is a pre-processing step.

    In your case, the compiler does not know what to use to replace X at compile time. The compiler needs to be sure about the type of X, because it needs to check it against T to validate the code. Hence the error…

    A solution to your issue is to replace < X > X with Object:

    public Object get(String property) { ... }
    

    and add a cast in:

    public T getObject() {
      return (T) get(OBJECT);
    }
    

    Your will get an unchecked-cast warning at compile time, but your code will compile (so yes your workaround is valid).

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

Sidebar

Related Questions

I have the following classes: public class Person { public String FirstName { set;
I have the following two classes: public class Address { public string AddressLine1 {
Let's say I have the following two classes: public class Person { public string
I have the following classes: package models; public class Test extends activejdbc.Model { }
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
I have following classes. class A { public: void fun(); } class B: public
I have the following Entity Framework POCO classes: public class Customer { public int
I have the following classes. public class B { public A a; public B()
I have the following 3 classes in my dbml file: public class Player {
I have the following classes: class Vertex { public: float X; float Y; float

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.