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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:02:11+00:00 2026-06-07T02:02:11+00:00

Sorry didnt know who to formulate the question best, but i will try to

  • 0

Sorry didnt know who to formulate the question best, but i will try to explain my Problem here, i have following class:

public class ReadOnlyTable<T extends Model> implements ReadOnly<T> {
...

protected ReadOnlyTable() {
    initTable();
}

protected void reloadDataSource() {
    initTable();
}

...

@Override
public ArrayList<T> findAll() {
    ArrayList<T> result = null;

    try {
        long startTime = System.currentTimeMillis();
        result = datasource.getAllEntries();
        //  // Logger.getLogger().write("FindAllQuery time was " + (System.currentTimeMillis() - startTime) + "ms");
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    return result;
}

Lets say T is class “Galaxy”, then i tried to loop over all elements in the returned Array, with following Code

    for (Galaxy gal : gDAO.findAll()) {

    }

Why does it give me an error that Galaxy is required, but Object is found?? What am i doing wrong, that i have return type ArrayList and not ArrayList<T>

EDIT 1:

gDAO is defined this way

private static GalaxyDAO gDAO = (GalaxyDAO) DAOFactory.get(GalaxyDAO.class);

And DAOFactory looks like this

    public static <T> T get(Class clazz) {
    if (!instanceList.containsKey(clazz)) {
        try {

            GenericDAO genericDAO = null;
            Constructor constructor;
            constructor = clazz.getDeclaredConstructor();
            constructor.setAccessible(true);
            genericDAO = (GenericDAO) constructor.newInstance();
            instanceList.put(clazz, genericDAO);

            return (T)genericDAO;
        } catch (NoSuchMethodException ex) {
            DebugBuffer.writeStackTrace(DAOFactory.class.getName(), ex);
        } catch (SecurityException ex) {
            DebugBuffer.writeStackTrace(DAOFactory.class.getName(), ex);
        } catch (InstantiationException ex) {
            DebugBuffer.writeStackTrace(DAOFactory.class.getName(), ex);
        } catch (IllegalAccessException ex) {
            DebugBuffer.writeStackTrace(DAOFactory.class.getName(), ex);
        } catch (InvocationTargetException ex) {
            DebugBuffer.writeStackTrace(DAOFactory.class.getName(), ex);
        }
    }else{
        return (T)instanceList.get(clazz);
    }

    return null;
}

and finally

public class GalaxyDAO extends ReadWriteTable<Galaxy> implements GenericDAO {

and yeah .. ReadWriteTable extends ReadOnlyTable

public abstract class ReadWriteTable<T extends Model> extends ReadOnlyTable implements ReadWrite<T> {
public ReadWriteTable() {              
    super();
}    

Appendix to acknowledged solution

I had a mistake in my inferfaces which prevented to give the Type to ReadOnlyTable see

public interface ReadWrite<T> extends ReadOnly {

instead of

public interface ReadWrite<T> extends ReadOnly<T> {

after fixing that i could also change following line

public abstract class ReadWriteTable<T extends Model> extends ReadOnlyTable<T> implements ReadWrite<T> {
  • 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-07T02:02:13+00:00Added an answer on June 7, 2026 at 2:02 am

    gDAO is an instance of your class ReadOnlyTable<T extends Model> ? What is it’s type parameter (how did you declare it)?

    It has to be Galaxy, otherwise it will not work.

    Update: Now that you posted more code, the problem is that you have to pass the type parameter Galaxy to the class ReadOnlyTable<T extends Model>, where the findAll method is, otherwise it doesn’t know what T is, and will return ArrayList<Object>.

    This line is the problem:

    public abstract class ReadWriteTable<T extends Model> extends ReadOnlyTable implements ReadWrite<T> 
    

    The class ReadOnlyTable also has to receive the type parameter:

    ReadOnlyTable<T extends Model>
    

    So the line has to be:

    public abstract class ReadWriteTable<T extends Model> extends ReadOnlyTable<T extends Model> implements ReadWrite<T> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry about the vague title, but i didnt know how to ask the question
Sorry for the title, I didnt know what's the best title for this question
Sorry i really didn't know how to phrase the question any better but here
Sorry, I know this question is easy, but I don't know how to get
sorry for asking this question again but i didnt get much help on the
Sorry for the question title, i didn t know how to explain the question
Sorry for the vague title, I didnt know how to explain it better. I
Sorry if this is a dupe, couldn't find it but didnt really know what
Sorry for the generic title of the question, but I didn't know how else
I didnt know how to word the question, so sorry if it doesnt really

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.