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

The Archive Base Latest Questions

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

I have two similar methods. One is intended to handle objects, the other vectors:

  • 0

I have two similar methods. One is intended to handle objects, the other vectors:

@SuppressWarnings("unused")
private void printRows(PrintWriter out, Vector<?> dataOb, 
        String[] columns, String[] columnType, 
        Hashtable<?, ?> columnAccessors, 
        String trOptions, String tdOptions)
    throws ServletException 
{
    System.out.println("At Printing Rows, Vector...");
    // If the object is a vector, loop through the elements.
        Vector<?> v = (Vector<?>) dataOb;
        Enumeration<?> e = (Enumeration<?>) v.elements();
        while (e.hasMoreElements())
        {
            tryRow(out, e.nextElement(), 
                        columns, columnType, columnAccessors, trOptions, tdOptions);
        }
}

private void printRows(PrintWriter out, Object dataOb, 
        String[] columns, String[] columnType, 
        Hashtable<?, ?> columnAccessors, 
        String trOptions, String tdOptions) 
    throws ServletException 
{
    System.out.println("At Printing Rows, Object...");
    // If the object is an array, loop through the objects.
        Object[] objects = null;
        try {objects = (Object[]) dataOb;}
        catch (Exception e1) { ExceptionToolkit.exceptionHandler (e1, "Can't assign data to objects"); }

        System.out.println("At Printing Rows, have objects...");
        for (Object object: objects)
            {
                System.out.println("At Printing Rows, have objects, looping...");
                tryRow(out, object, columns, columnType, columnAccessors, trOptions, tdOptions); 
            }
}

If I understand Java and polymorphism correctly, if a call the method with a vector, the first function should be called, but if I call it with anything else which is an object, the second method should be called.

However, when my program goes to call the function, somehow it is getting the wrong one because instead of processing correctly, I get this:

CLASS: class hu.flux.models.PersonColumn: name
CLASS: class hu.flux.models.PersonColumn: phone
At Printing Rows, Object...
Can't assign data to objects: java.lang.ClassCastException: java.util.Vector cannot be cast to [Ljava.lang.Object;
java.lang.ClassCastException: java.util.Vector cannot be cast to [Ljava.lang.Object;
    at hu.flux.tables.TableServlet.printRows(TableServlet.java:97)
    at hu.flux.tables.TableServlet.service(TableServlet.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:674)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:579)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:516)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:930)
    at org.apache.jsp.ShowPeople_jsp._jspService(ShowPeople_jsp.java:68)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:376)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:674)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:462)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:401)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
    at hu.flux.ControllerServlet.gotoPage(ControllerServlet.java:84)
    at hu.flux.ControllerServlet.service(ControllerServlet.java:47)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:163)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:556)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:267)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:245)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:260)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
At Printing Rows, have objects...

If I understand the stacktrace correctly, it is telling me that it is failing because dataOb is a vector, but if this is true, shouldn’t the other method have caught the call?

Did I misunderstand something about Java’s polymorphism? Should something in the signature be different? Do I really need to check whether the object is an instance of vector before calling that specific function, instead of relying on polymorphism to handle the distinction? Is there a good way to fix this problem from within one or the other of the printRows() methods?

  • 1 1 Answer
  • 3 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-17T22:21:02+00:00Added an answer on May 17, 2026 at 10:21 pm

    You haven’t provided quite enough info, so I am guessing a bit… if what I am saying here doesn’t apply please let me know. It would be useful to the the code that calls printRows…

    If you do this:

    Object x = new Vector();
    
    printRows(..., x);
    

    then the printRows(…, Object) method will be called because the resolution of what method to call is done at compile time not runtime. The compiler decides what method to call based on the type of the variable is declared. At no time, when choosing what method to call, does anything look at the value that is in the object.

    You can fix this putting code like this at the top of the printRows(…, Object) method:

    if(x instanceof Vector)
    {
        printRows(out, (Vector)dataOb);
    }
    else
    {
       ....
    }
    

    This is similar to this question.

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

Sidebar

Related Questions

I have two objects which use really similar methods, save for one line. For
I have the following two methods that (as you can see) are similar in
I have two similar codes. The first one works as expected. urlpatterns = patterns('',
I have two files, one with content similar to the following: 1.something344343 2.something2dsdsf 4.somethingdsddfsd
I have two similar methods that take a criteria object (dumb object with a
I have two very similar methods: public IQueryable<User> Find(Func<User, bool> exp) { return db.Users.Where(exp);
I have two very similar usecases, one works, and another one does not. I
I have some methods advised by two aspects, one is using the spring AOP
In my Asp.net MVC app, I have two methods on a controller, one for
I have two similar (not identical) dlls, one of them being actually a part

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.