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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:41:12+00:00 2026-06-17T21:41:12+00:00

I am very familiar with functional langauges such as Scheme, and Haskell. I’m trying

  • 0

I am very familiar with functional langauges such as Scheme, and Haskell. I’m trying to solve a problem in Java and struggling, possibly because I’m still in a functional mindset.

I want to write:

public void doQueryAndStoreData(String query, <? extends Collection> storeIn) {
    /* make a jdbc query, get ResultSet */
    ResultSet rset = ...;
    ProcessResultSet proc = new ProcessResultSet();
    proc.process(rset, storeIn);
    /* clean up */
}

with an interface like:

private interface IProcessResultSet<C> {
    public void process(ResultSet rset, C storeIn);
}

and a class implementing the interface like:

private class ProcessResultSet implements IProcessResultSet<? extends Collection> {
    public void process(ResultSet rset, Map storeIn) {
        /* do something */
    }

    public void process(ResultSet rset, List storeIn) {
        /* do something else */
    }
}

so that the first method can call the appropriate process based on what type of storeIn it’s given.

In Haskell I could write

class Storeable c a where
    store :: a -> c a -> c a

doQueryAndStoreData :: Storeable c a => ResultSet a -> c a -> c a
doQueryAndStoreData (ResultSet rs) coll = foldr store coll rs

and provide Storeable instances for whatever collection type I want to store my ResultSet in.

Is this the correct approach in Java? Because I feel like I’m somewhat fighting the langauge to accomplish this.

  • 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-17T21:41:13+00:00Added an answer on June 17, 2026 at 9:41 pm

    No, Java doesn’t do that.

    You’d need to do something like:

    public <T> void doQueryAndStoreData(
        String query,
        T storeIn,
        ResultSetProcessor<T> processor
    ) {
    

    Or much more likely:

    public void doQueryAndStoreData(
        String query,
        ResultSetHandler handler // may contain processor and storeIn
    ) {
    

    I hope I don’t need to mention SQL injection vulnerabilities are a bad thing. (Also Map is not a Collection in Java (it is in C# but C# Collection isn’t very useful).)

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

Sidebar

Related Questions

I am very familiar with C# but starting to work more in Java. I
I have not used jquery much yet and not very familiar with it. Trying
I am not very familiar with Python. I am trying to extract the artist
Coming from a C/C++ background, I'm not very familiar with the functional style of
I am not very familiar with java-script/ jquery. i am creating a sliding social
I am very familiar with Java and this is allowed there. However it looks
I'm not sure why this isn't working but probably because I'm not very familiar
I am trying to compute using two loops. But I am not very familiar
Given this very familiar model of prototypal construction: function Rectangle(w,h) { this.width = w;
i'm really not very familiar with CSS and HTMl so take it easy with

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.