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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:51:22+00:00 2026-06-10T14:51:22+00:00

In Java the abstract version of a Reader that works with pulling Objects (instead

  • 0

In Java the abstract version of a Reader that works with pulling Objects (instead of characters) is an Iterator.

The question is there an abstract version of Appendable or Writer where I can push objects (ie an interface)?

In the past I just make my own interface like:

public interface Pusher<T> {
    public void push(T o);
}

Is there a generic interface that is available in most environments that someone knows about that makes sense so I don’t have to keep creating the above interface?

Update:

Here is an example of where it would be useful:

public void findBadCategories(final Appendable a)  {
    String q = sql.getSql("product-category-bad");
    jdbcTemplate.query(q, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs) throws SQLException {
            String id = rs.getString("product_category_id");
            String name = rs.getString("category_name");
            if (! categoryMap.containsKey(id)) {
                try {
                    a.append(id + "\t" + name + "\n");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    });
}

I’m using an Appendable here but I would much rather have my Pusher callback. Believe me once Java 8 comes out I would just use closure but that closure still needs an interface.

Finally the other option I have chosen before is to completely violate Guava’s Predicate or Function (although that seems even worse). Its violation of the contract because these aim to be idempotent (although I suppose if you return true all the time… ).

What Guava does provide though is sort of analagous to Python’s generators thanks to its AbstractIterator.

I added an enhancement issue to Guava but I agree with them that its not really their job to add something fundamental like that.

  • 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-10T14:51:24+00:00Added an answer on June 10, 2026 at 2:51 pm

    Here is what I decided to do (and I think its the best option out of what others gave 😛 ).

    I’m going to backport Java 8’s Lambda classes (java.util.functions.*). Particularly this one:

    /**
     * Performs operations upon an input object which may modify that object and/or
     * external state (other objects).
     *
     * <p>All block implementations are expected to:
     * <ul>
     * <li>When used for aggregate operations upon many elements blocks
     * should not assume that the {@code apply} operation will be called upon
     * elements in any specific order.</li>
     * </ul>
     *
     * @param <T> The type of input objects to {@code apply}.
     */
    public interface Block<T> {
    /**
     * Performs operations upon the provided object which may modify that object
     * and/or external state.
     *
     * @param t an input object
     */
    void apply(T t);
    
    // Some extension methods that I'll have to do with below.
    }
    

    Basically I’ll make a new namespace like com.snaphop.backport.java.util.functions.* and move over the interfaces and make them work with Guava. Obviously I won’t have the lambda syntax or the extension methods but those I can work around. Then in theory when Java 8 comes out it all I would have to do is a namespace switch.

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

Sidebar

Related Questions

I know abstract fields do not exist in java. I also read this question
I'm new to Java and I have a beginner question: NumberFormat is an abstract
I'm looking at some Java classes that have the following form: public abstract class
I have an abstract java class that implements a couple of its methods, but
Java doesn't support multiple inheritance for abstract classes, but I'm trying to do the
I'm writing an abstract class in Java where I'd like a parameter of one
I'm learning Java and as I know only abstract classes and interfaces cannot be
Possible Duplicate: Creating an abstract class in Objective C In Java I like to
In Effective Java , Joshua Bloch favors interfaces over abstract classes. However, he notes
I am creating a partially ordered set as an abstract data type in java,

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.