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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:00:00+00:00 2026-06-14T04:00:00+00:00

I have public class Entity On which works class: public class Table<Target extends Entity>

  • 0

I have

public class Entity

On which works class:

public class Table<Target extends Entity>
{
    public boolean save (Target target)
    public Target load (int id)
}

Till i put this objects of Table class in Database class Map everything is ok but:

public class Database
{
    public String name;
    public Map<String, Table<? extends Entity>> tables = new HashMap <String, Table<? extends Entity>> ();
    public Context context;
    public int version;
    public Database (Context context, int version)
    {
        this.context = context;
        this.version = version;
    }
    public void add (Table<? extends Entity> table)
    {
        tables.put(table.name, table);
    }
    public Table <? extends Entity> table (String name)
    {
        return (Table<? extends Entity>) tables.get(name);
    }

}

Assume we have:

 public class Apple extends Entity

I want this code to work:

    //init      
    database = new Database(getBaseContext(), 4);
    new Table<Apple> (database, Apple.class);

    //this is where solution need occurs !
    database.table("apples").save (new Apple("green apple"));

The method save(capture#1-of ? extends Entity) in the type
Table(capture#1-of ? extends Entity)
is not applicable for the arguments (Note)

How to make the map.get method work ?

  • 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-14T04:00:00+00:00Added an answer on June 14, 2026 at 4:00 am

    One thing you can do to make this more convenient is map the tables by the target class:

    Map<Class<? extends Entity>, Table<? extends Entity>> tables;
    
    public void <T extends Entity> addTable(Class<T> cls, Table<T> table) {
        tables.put(cls, table);
        // alternately make it possible to get the target class from the table
    }
    
    @SuppressWarnings("unchecked")
    public <T extends Entity> Table<T> getTable(Class<T> cls) {
        return (Table<T>) tables.get(cls);
    }
    

    As the annotation implies, this isn’t at all typesafe – you’ll need to make sure you never mismatch the keys and values in tables.

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

Sidebar

Related Questions

I have an abstract entity: public abstract class Entity extends JPanel implements FocusListener And
I have the 2 following entities: @Entity @Table(name = brand) public class Brand {
I have a code first application which defined like this: public abstract class Entity
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
I have an entity similar to the below: public class Entity { public List<DateItem>
I have the following classes: public class Entity<T> where T : Entity<T> { public
I have class with back reference: public class Employee : Entity { private string
Imagine I have an entity: public class MyObject { public string Name { get;
I have the following classes in my Model: public abstract class Entity : IEntity
I have two classes, user and role, defined as: public class User : Entity

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.